Angular: Bind to an @Input alias

Viewed 25737

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?

4 Answers

You should rename @Input('appAvatarColor') name: string; to something else for this to differ from the directive name. You can do @Input('avatarColor') name: string; and then simplify it by @Input() avatarColor: string;

The right way to do it should be the following:

@Input() appAvatarColor: string;
Related