属性的使用
1.给子组件一个名称
<app-content #content></app-content>
2.父组件中配置
//app.tsimport { Component,ViewChild } from '@angular/core';export class AppComponent { @ViewChild('content',{static:false}) content:any;}
3.子组件中的属性
//content.tsexport class ContentComponent implements OnInit {msg:string='我是你孩儿' constructor() { } ngOnInit() { }}
4.父组件中使用
//app.html<app-content #content></app-content><p>{{content.msg}}</p>
方法的使用
//content.jsexport class ContentComponent implements OnInit {run(){ console.log("这是子组件的方法")}}
//app.html<p>{{content.run()}}</p>