How to use @HostBinding with @Input properties in Angular 2?

前端 未结 5 1644
青春惊慌失措
青春惊慌失措 2020-12-29 20:27

(Angular 2 RC4)

With @HostBinding we should be able to modify properties of the host, right? My question is, does this apply to @Input() properties as well and if so

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-29 20:46

    (1) declare hostbinding property with input property.

    @HostBinding('attr.aaa') @Input() aaa: boolean = false;
    

    (2) set hostbinding property to input property

    @Input() aaa: string;
    @HostBinding('attr.bbb') ccc: string;
    
    ngOnInit(){
      this.ccc = this.aaa;
    }
    

提交回复
热议问题