首页 > 其他 > 详细

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

时间:2019-12-05 20:56:27      阅读:135      评论:0      收藏:0      [点我收藏+]

父组件: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();
}

}

 

 

 

 

 





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

原文:https://www.cnblogs.com/fpcing/p/11991771.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!