2017-04-02 80 views
1

請幫我解決下面的錯誤。在RouterLink上獲取模板分析錯誤。 請分享在角度2中使用RouterLink的正確方法。模板解析錯誤:解析器錯誤:意外的令牌 - RouterLink

 Unhandled Promise rejection: Template parse errors:Parser Error: Unexpected token/at column 2 in [[/events]] in ng:///t/[email protected]:46 ("r"> 
       <ul class="nav nav-sidebar"> 
        <li class="active"><a [ERROR ->][routerLink]="[/events]">Events</a></li> 
        <li><a [routerLink]="[/task"]>Tasks<"): ng:///t/[email protected]:46Parser Error: Unexpected token/at column 2 in [[/events]] in ng:///t/[email protected]:46 ("ebar">      <ul class="nav nav-sidebar"> 
        <li class="active">[ERROR ->]<a [routerLink]="[/events]">Events</a></li> 
        <li><a [routerLink]="[/task"]>Tas"): ng:///t/[email protected]:43, Directive tParser Error: Unexpected token/at column 2 in [[/events]] in ng:///t/[email protected]:46 ("ebar"> 
       <ul class="nav nav-sidebar"> 

回答

3

你有語法錯誤,您正在使用:

<a [routerLink]="[/events]" ... > 

而是它應該是:

<a [routerLink]="['/events']" ... > 

<a routerLink="/events" ... > 
+0

感謝它的工作 –

+0

上加載HTML文件的任何想法的WebPack –

0

語法錯誤符號/不是一個字符串。在字符串周圍添加引號以解決錯誤。 []用於數組聲明(在值上),如果使用它,則添加字符串值,否則不需要數組只是使用默認情況下HTML中的字符串屬性值。在Angular發佈的最新版本中,您也不需要routerLink[]的綁定。

所以,代碼簡化爲

<a routerLink="/events">Events</a>