Angular 2 @Output参数
发布时间:2020-12-17 07:32:40 所属栏目:安全 来源:网络整理
导读:我试图通过@Output传递参数,但被激活的函数只是接收’undefined’.有人可以告诉我通过@Output的EventEmitter传递参数的方法吗?例如: var childCmp = ng.core.Component({ selector:'child-cmp',outputs: ['myEvent'] }).Class({ constructor: function(){
我试图通过@Output传递参数,但被激活的函数只是接收’undefined’.有人可以告诉我通过@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自定义事件时提供的值. 希望它能帮到你,蒂埃里 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |