Angular: bind to @Input alias
I am trying to set an input alias in a directive following this example
@Input('appAvatarColor') name: string;
The program works, but I get this warning from TS Lint
the directive's input property should not be renamed
The directive selector is
@Directive({
selector: '[appAvatarColor]'
})
Am I doing something wrong?
Why is this considered bad practice by default?
source to share
You can disable the rule in tslint.json
"no-input-rename": false
or disable checking only a certain line, for example:
// tslint:disable-next-line:no-input-rename
@Input('appAvatarColor') name: string;
My question is, why is this considered bad practice by default?
-
Two names for the same property (one private, one public) are inherently confusing.
-
You must use an alias when the directive name is also an input property and the directive name does not describe the property.
From https://angular.io/docs/ts/latest/guide/style-guide.html#!#05-13
source to share