ViewChild

1、子组件

  1. //.ts
  2. export class ContentComponent implements OnInit {
  3. public msg:string = "我是子组件"
  4. constructor() { }
  5. ngOnInit() {
  6. }
  7. }

2、父组件

  1. //父组件
  2. .html
  3. <app-content #content></app-content>
  4. <p>{{content.msg}}</p>
  1. //.ts
  2. import { Component, ViewChild } from '@angular/core';
  3. ...
  4. export class AppComponent {
  5. title = 'my-ng-app02';
  6. @ViewChild('content',{static:false}) content:any
  7. }