2017-09-07 37 views
0

我想在我的html頁面中顯示下面的代碼片段。我使用的角度我已經在我的模板中添加以下2代碼標記不能在角度html模板中工作

{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 ->]"): [email protected]:6 
Invalid ICU message. Missing '}'. (" 
     </ngb-tab> 
    </ngb-tabset> 
</div>[ERROR ->]"): [email protected]:6 

回答

2

錯誤消息提供瞭解決方案。執行以下操作:

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

通過插值它將返回一個帶有內容的字符串。

+0

謝謝。它爲我工作。所以,這個問題是有棱角的,因爲它在代碼標籤內部時感到困惑。 –

0

Angular試圖將其解析爲表達式您必須如下所示轉義'{'括號。

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