【发布时间】:2019-06-08 18:22:29
【问题描述】:
我一直在尝试从指令绑定中访问 href 值,但没有任何运气。
<a class="u-link-default" [attr.href]="tosUrl">Terms</a>
指令
@Directive({
selector: 'a'
})
export class ExternalLinkDirective implements OnInit, OnChanges {
@Input() href: string;
@HostBinding('rel') rel: string;
@HostBinding('target') target: string;
constructor() {}
ngOnInit() {
console.log(this.href); // no value
}
ngOnChanges() {
console.log(this.href); // no value
}
}
PD:<a class="u-link-default" href="https://fakedomain.com">Terms</a> 有效,我已经检查过“tosUrl”不为空。
【问题讨论】:
标签: angular binding angular2-directives