简体   繁体   English

为@Output() 和@Input() 分配别名显示 TSLint 错误

[英]Assigning an Alias to @Output() and @Input() show TSLint Error

I'm trying to assign an alias to @Output but there are TSLint error,我正在尝试为 @Output 分配一个别名,但出现 TSLint 错误,

export class CockpitComponent implements OnInit {
  @Output('bpCreated') blueprintCreated = new EventEmitter<{ serverName: string, serverContent: string }>();
  @Output('srvCreated') serverCreated = new EventEmitter<{ serverName: string, serverContent: string }>();

TSLint: In the class "CockpitComponent", the directive output property "serverCreated" should not be renamed.Please, consider the following use "@Output() serverCreated = new EventEmitter();" TSLint:在类“CockpitComponent”中,指令输出属性“serverCreated”不应重命名。请考虑以下使用“@Output() serverCreated = new EventEmitter();” (no-output-rename) (无输出重命名)

so when should Assign an Alias to @Output() and @Input() in Angular?那么什么时候应该在 Angular 中为@Output()@Input()分配别名?

Tslint 错误片段

This is tsLint error, and it's clear says you should not rename it so这是tsLint错误,很明显你不应该重命名它

either任何一个

@Output() blueprintCreated ...

or要么

@Output() bpCreated ...

or if you insist to have it add this comment on top of each lines and it will ignore it或者如果你坚持让它在每一行的顶部添加这个评论,它会忽略它

// tslint:disable-next-line:no-output-rename
@Output('bpCreated') blueprintCreated

you can enable the tslint from Webstorm Preferences (and Suppress error for current line)您可以从 Webstorm 首选项启用 tslint(并抑制当前行的错误)

I did this in my code:我在我的代码中这样做了:

// tslint:disable-next-line:no-output-native
@Output() close = new EventEmitter();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM