angular 父组件和子组件
angular4中父组件如何传递子组件的方法 原文链接 https://blog.csdn.net/u012396955/article/details/78852140 子组件ts export class ChildComponent implements OnInit { constructor() { } ngOnInit() { } greeting(name:string){ console.log('hello'+name); } } 父组件模板 <!--1.在控制器里用typescript代码实现--> <app-child #child1></app-child> <!--2.在模板上用模板变量实现--> <app-child #child2></app-child> <button (click)="child2.greeting('**Jerry**')">按钮调用child2的greeting方法</button> 父组件调用 export class AppComponent implements OnInit{ @ViewChild('child1') child1:ChildComponent; ngOnInit(): void { this.child1.greeting('*tom*'); } } 结果 hello *tom* hello *