angular8 大地老师学习笔记---第九课

父组件:news组件

<app-header [title]="title"  [msg]="msg" [run]='run' [home]='this'></app-header>

<div>我是首页组件</div>

 

子组件:header组件

import { Component, OnInit,Input} from '@angular/core';

@Component({
selector: 'app-header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.scss']
})
export class HeaderComponent implements OnInit {

//接受父组件传来的数据
@Input() title:any;

@Input() msg:any;

@Input() run:any;

@Input() home:any;

constructor() { }

ngOnInit() {}

getParentMsg(){
//获取父组件的数据
alert(this.msg);
}

getParentRun(){
//执行父组件的run 方法
// this.run();
alert(this.home.msg);
this.home.run();
}

}

 

 

 

 

 





posted @ 2019-12-05 20:39  fpc  阅读(400)  评论(0编辑  收藏  举报