我试图通过@Output 传递参数,但被激发的函数只收到“未定义”。有人可以告诉我如何通过@Output 的 EventEmitter 传递参数吗?例如:
var childCmp = ng.core.Component({
selector:'child-cmp',
outputs: ['myEvent']
}).Class({
constructor: function(){
this.myEvent = new ng.core.EventEmitter();
this.myEvent.emit(false);
}
});
var parentCmp = ng.core.Component({
selector:'parent-cmp',
template:'<child-cmp (myEvent)="invoke()"'></child-cmp>',
directives: [childCmp]
}).Class({
constructor:function(){},
invoke: function(flag){
// here flag is undefined!!
}
});
最佳答案
您应该使用以下方法获取事件提供的值:
<child-cmp (myEvent)="invoke($event)"'></child-cmp>'
这样,您的 childCmp
的 invoke
方法将接收您在发出 myEvent
自定义事件时提供的值作为参数。
希望对你有帮助, 蒂埃里
关于Angular 2 @Output 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34917932/