2016-03-23 59 views
0

進出口試圖routerLink屬性綁定到使用@ Component.host a元件 '[routerLink]'聲明,但是它崩潰:Angular2主機:{ '[routerLink]': '/富'}

EXCEPTION: Error: Uncaught (in promise): Template parse errors: Can't bind to 'routerLink' since it isn't a known native property ("[ERROR ->]"): [email protected]:0

它正常工作與
template: '<a [routerLink]="['/Matches', 'MatchesDetail', { match: id }]">{{id}}</a>'

組件代碼:

import { RouterLink } from 'angular2/router' 

@Component({ 
    directives: [RouterLink], 
    selector: 'a[match]', 
    template: `{{id}}`, 
    host: { 
     '[routerLink]': "['/Matches', 'MatchesDetail', { match: id }]" 
    } 
}) 

的一點是讓^ h TML是這樣的:

<a href="/matches/1234">1234</a>

相反的:

<match><a href="/matches/1234">1234</a></match>

什麼我錯了嗎?謝謝。

+0

你可以給你使用這個組件的方式嗎?謝謝! –

+0

無論如何,將它添加到'host:'的目的是什麼? –

+0

它可以是''父母組件模板中的某處。我通過DCL使用這個組件'this.dcl.loadIntoLocation(Match,this.elementRef,'componentAnchor')' –

回答

0

使用routerLink這種方式是無效的。這種方式不支持使用routerLink。這是一個要添加到元素標記的指令,而不是一些特殊的綁定語法。

host: { 
    '[routerLink]': "['/Matches', 'MatchesDetail', { match: id }]" 
}