내장 된 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);
}
}
내가이 지침의 인스턴스를 만들려고 오전 :
Can't bind to 'customRouterLink' since it isn't a known property of 'a'.
다음 오류의 원인이되는
<a [customRouterLink]="'http://www.google.com'">custom link</a>
그러나 내가 extends RouterLinkWithHref
을 제거하면 m 지시어 정의가 작동합니다.
예 plunkers :
CustomLinkDirective extends RouterLinkWithHref
-RouterLinkWithHref
을 확장하지 Shows error aboveCustomLinkDirective
-Directive created without error 당신은 당신의 모듈의declarations
에CustomLinkDirective
을 추가하거나 더 나은CustomLinkDirective
에 대한 모듈을 만들고 추가 할 필요가
결국 문제를 해결 했습니까? 비슷한 것을 시도하고 있었다. – Ryan