Javascript $events变量是否可以在Angular中重命名?
我有以下角度分量:Javascript $events变量是否可以在Angular中重命名?,javascript,angular,events,Javascript,Angular,Events,我有以下角度分量: import { Component, OnInit , EventEmitter , Output } from '@angular/core'; @Component({ selector: 'app-corkpit', templateUrl: './corkpit.component.html', styleUrls: ['./corkpit.component.css'] }) export class CorkpitComponent impleme
import { Component, OnInit , EventEmitter , Output } from '@angular/core';
@Component({
selector: 'app-corkpit',
templateUrl: './corkpit.component.html',
styleUrls: ['./corkpit.component.css']
})
export class CorkpitComponent implements OnInit {
/*
@Output is used when you need to emit an event from a child
component to the parent (Opp. to what @Input does in the server component !)
*/
@Output() serverCreated = new EventEmitter<{ serverName: string , serverContent: string }>();
@Output() blueprintCreated = new EventEmitter<{ serverName: string , serverContent: string }>();
newServerName = '';
newServerContent = '';
constructor() { }
ngOnInit() {
}
onAddServer() {
this.serverCreated.emit({
serverName : this.newServerName ,
serverContent: this.newServerContent
})
}
onAddBlueprint() {
this.blueprintCreated.emit({
serverName : this.newServerName ,
serverContent: this.newServerContent
})
}
}
现在,在父组件的模板文件中,我有以下标记:
<app-corkpit
(serverCreated)="onServerAdded($event)"
(blueprintCreated)="onBlueprintAdded($event)"
></app-corkpit>
现在,如果我将此
$event
更改为$data
我的应用程序会中断,那么我的问题是此$event
变量是否可以重命名为我喜欢的任何变量?就像在jQuery中一样,如果函数接受一个事件作为参数,它可以是event
,也可以是e
,或者我喜欢的任何东西 除了分叉Angular存储库并修改其代码外,无法重命名$event
重命名也没有意义,因为这只会让其他人更难理解代码,而没有任何值得一提的好处。我认为您无法重命名$event。因为它不像函数中的参数名。引用这些链接可能会有所帮助,为什么要更改?@LogicBlower谢谢。。。。维加,没有理由,只是好奇而已。
<app-corkpit
(serverCreated)="onServerAdded($event)"
(blueprintCreated)="onBlueprintAdded($event)"
></app-corkpit>
onServerAdded($event)