代码标记在角度html模板中不起作用

问题描述 投票:1回答:2

我想在我的html页面中显示以下代码段。我正在使用角度2。

{path: 'test', component: TestComponent}

我在下面的模板中添加了以下内容:

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

当我加载模板时,我看到下面的错误。我该如何解决?我不能使用代码标签吗?

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
html5 angular angular2-template
2个回答
2
投票

错误消息提供了解决方案。请执行下列操作:

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

通过插值,它返回带有内容的字符串。


2
投票

Angular试图将其解析为表达式你必须转义'{'括号,如下所示。

<pre>
<code>{{'{'}}path: 'test', component: TestComponent{{'}'}}</code>
</pre>
© www.soinside.com 2019 - 2024. All rights reserved.