Code tag is not working in angular html template

允我心安 提交于 2020-01-11 07:18:24

问题


I would like to display the below snippet in my html page. I'm using angular 2.

{path: 'test', component: TestComponent}

I've added below in my template to achieve this:

<pre>
<code>{path: 'test', component: TestComponent}</code>
</pre>

When I load the template, I see below error. How do I fix this? Can't I use code tag?

directive_normalizer.js:127 Uncaught Error: Template parse errors:
Unexpected character "EOF" (Do you have an unescaped "{" in your template? Use "{{ '{' }}") to escape it.) ("
        </ngb-tab>
    </ngb-tabset>
</div>[ERROR ->]"): TestComponent@31:6
Invalid ICU message. Missing '}'. ("
        </ngb-tab>
    </ngb-tabset>
</div>[ERROR ->]"): TestComponent@31:6

回答1:


The error Message provides the solution. Do the following:

<pre>
<code>{{"{path: 'test', component: TestComponent}"}}</code>
</pre>

Through interpolation it returns a string with the content.




回答2:


Angular is trying to parse it as expression You have to escape the '{' braces as shown below.

<pre>
<code>{{'{'}}path: 'test', component: TestComponent{{'}'}}</code>
</pre>


来源:https://stackoverflow.com/questions/46090040/code-tag-is-not-working-in-angular-html-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!