public test(){
//some code.....
}
<app-child (eventfire)="test($event)"></app-child>
@Output() eventfire= new EventEmitter<string>();
calltoParent(): void {
debugger;
this.eventfire.next();
}
<button mat-raised-button (click) = calltoParent($event);>Click Here<button>//This already show in grid
答案 0 :(得分:3)
您可以使用output
和EventEmitter
来实现。更新以下代码:
在parent.component.html
中,添加带有触发事件的子选择器:
<app-child (clicked)="test()"></app-child>
在parent.component.ts
中添加test
方法:
test(){
alert('parent function called from child!')
}
现在在child.component.ts
中添加以下代码:
@Output() clicked = new EventEmitter();
callParent(){
this.clicked.emit()
}
点击按钮时触发callParent
方法:
<button (click)="callParent()"> click </button>
这是工作示例:StackBlitz