routerLink
ビルトインディレクティブを拡張して、customRouterLink
という独自のディレクティブを作成したいと考えています。アトリビュートディレクティブの拡張
は、私は単にRouterLinkWithHref
を拡張するクラスを作成している:
@Directive({
selector: 'a[customRouterLink]'
})
export class CustomLinkDirective extends RouterLinkWithHref {
constructor(router: Router, route: ActivatedRoute, locationStrategy: LocationStrategy) {
super(router, route, locationStrategy);
}
@Input()
set customRouterLink(data: any[]|string) {
console.log("custom directive input", data);
}
}
を私はこのディレクティブのインスタンスを作成しようとしています:
次のエラーの原因になっている<a [customRouterLink]="'http://www.google.com'">custom link</a>
:
Can't bind to 'customRouterLink' since it isn't a known property of 'a'.
ただし、私がextends RouterLinkWithHref
を削除した場合mディレクティブの定義は動作します。
例plunkers:
CustomLinkDirective extends RouterLinkWithHref
からRouterLinkWithHref
を延長しないShows error aboveCustomLinkDirective
からDirective created without errorあなたのモジュールのdeclarations
にCustomLinkDirective
を追加したり、より良いCustomLinkDirective
ためのモジュールを作成して追加する必要が
これを最後に解決しましたか?同様のことをしているのを見ていました – Ryan