Angular: Bind to an @Input alias

后端 未结 4 1359
一整个雨季
一整个雨季 2021-02-06 22:21

I\'m trying to set an input alias in a directive following this example

  @Input(\'appAvatarColor\') name: string;

The program is working, but

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-06 23:09

    You can either turn off rule in tslint.json

    "no-input-rename": false
    

    or disable checking for only specific line like:

    // tslint:disable-next-line:no-input-rename
    @Input('appAvatarColor') name: string;
    

    My question is why is this considered a bad practice by default?

    • Two names for the same property (one private, one public) is inherently confusing.

    • You should use an alias when the directive name is also an input property, and the directive name doesn't describe the property.

    From https://angular.io/docs/ts/latest/guide/style-guide.html#!#05-13

提交回复
热议问题