【发布时间】:2017-06-03 07:50:49
【问题描述】:
我有一个嵌套组件,我希望将一些数据直接发送到父打字稿文件而不通过模板。 我不能使用 <child (childEvent)="parentFunc()"></child>
这可能吗?如果是这样,怎么做?
这是事物的当前状态。
parent.component.html(元素必须是这个)
<child #child> </child>
parent.component.ts
@ViewChild('child') public child;
public doSomething() {
this.child.work();
}
public doThisWhenChildEmits(someData) {
//?????How do I call this function from child without going through the DOM
alert(It worked)
}
child.component.ts
@Output() private childEvent: EventEmitter<any> = new EventEmitter()
...
public work() {
// does some work that changes the child's template
}
public clickToSendBack(){
// click event that sends back to parent.component directly????
this.childEvent.emit(someData);
}
【问题讨论】:
标签: templates angular components parent-child emit