【发布时间】:2017-08-08 13:03:01
【问题描述】:
对于我的新手问题,我很抱歉,我正在尝试使用 @Output EventEmitter 将事件从子组件发送到父组件。我无法在我的父组件中捕获该事件。
子组件
@Component({
selector: 'app-new-attachment',
templateUrl: './new-attachment.component.html',
styleUrls: ['./new-attachment.component.css']
})
class NewAttachmentComponent {
@Input('attachment') attachment: any;
@Output() doneEditingAttachment:EventEmitter<boolean> = new EventEmitter<boolean>();
submit() {
console.log('done editing child');
this.doneEditingAttachment.emit(true);
}
}
父组件
@Component({
selector: 'app-new-article',
templateUrl: './new-article.component.html',
styleUrls: ['./new-article.component.css']
})
class NewArticleComponent {
newAttachment: any = {};
doneEditingAttachment($event) {
console.log('done editing parent ', $event);
}
}
我希望有
完成编辑子
还有一个
完成编辑父项
但我只完成了对孩子的编辑
【问题讨论】:
-
html 长什么样子?
-
@Sajeetharan
我已经想通了:我忘了添加子html中的事件
标签: javascript angular typescript angular2-components