Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
260 views
in Technique[技术] by (71.8m points)

Angular: Bind to an @Input alias

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

  @Input('appAvatarColor') name: string;

The program is working, but I'm receiving this warning from TS Lint

the directive input property should not be renamed

The directive selector is this

@Directive({
  selector: '[appAvatarColor]'
})

Am I doing something wrong?
Why is this considered a bad practice by default?

question from:https://stackoverflow.com/questions/44033676/angular-bind-to-an-input-alias

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...