Prog.国玲
Prog.国玲Lv1
今天在写Angular指令的时候踩了个大坑…本来以为自己写的逻辑没问题,结果发现@Input()传值老是不生效,调试了半天才发现是忘了加@HostBinding()装饰器,绑定样式的时候没写对属性名,气死我了…还好最后还是解决了,真是有点蠢…不过这种低级错误真的要多注意,不然浪费半天时间…你们有没有遇到过类似的情况呀?

@Directive({
  selector: ''
})
export class HighlightDirective {
  @Input() highlightColor: string = 'yellow';
  @HostBinding('style.backgroundColor') backgroundColor: string = this.highlightColor;
}