角度:绑定到@Input别名 [英] Angular: Bind to an @Input alias
问题描述
The program is working, but I'm receiving this warning from TS Lint
指令输入属性不应重命名
the directive input property should not be renamed
指令选择器是这个
@Directive({
selector: '[appAvatarColor]'
})
我做错什么了吗?
为什么默认情况下会将此视为不良做法?
Am I doing something wrong?
Why is this considered a bad practice by default?
推荐答案
您可以在 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.
来自 https://angular.io/docs/ts/latest/guide/style-guide.html#!#05-13
这篇关于角度:绑定到@Input别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!