Angular HTML binding

后端 未结 21 2637
暖寄归人
暖寄归人 2020-11-21 04:00

I am writing an Angular application and I have an HTML response I want to display.

How do I do that? If I simply use the binding syntax {{myVal}} it en

21条回答
  •  北荒
    北荒 (楼主)
    2020-11-21 04:50

    On angular2@2.0.0-alpha.44:

    Html-Binding will not work when using an {{interpolation}}, use an "Expression" instead:

    invalid

    -> throws an error (Interpolation instead of expected Expression)

    correct

    -> this is the correct way.

    you may add additional elements to the expression, like:

    hint

    HTML added using [innerHTML] (or added dynamically by other means like element.appenChild() or similar) won't be processed by Angular in any way except sanitization for security purposed.
    Such things work only when the HTML is added statically to a components template. If you need this, you can create a component at runtime like explained in How can I use/create dynamic template to compile dynamic Component with Angular 2.0?

提交回复
热议问题