html - 代码标签在 Angular html 模板中不起作用

标签 html angular angular2-template

我想在我的 html 页面中显示以下代码段。我正在使用 Angular 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

最佳答案

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

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

通过插值,它返回一个包含内容的字符串。

关于html - 代码标签在 Angular html 模板中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46090040/

相关文章:

html - 如何在右侧移动导航栏元素

html - 使用 z-index 使 div 高于另一个 div

javascript - 在变量中使用 html

javascript - 如何使用 JS/jQuery 在 HTML5 中使用 <audio> 标签播放一首又一首轨道?

angular - 如何从我的应用程序组件中的 auth.service 获取 isLoggedIn bool 值

javascript - Angular 2 - Auth0

javascript - Angular 2 Material : sidenav toggle from component

typescript - 在 Angular2 rc1 中基于路由隐藏元素

angular - 如何使用 ionic-3 中的表单数据对图像文件发出发布请求

Angular 2 组件 : How to handle circular Inputs and Outputs