1. 父组件调用子组件的时候传入数据
<app-header [msg]="msg"></app-header>
2. 子组件引入 Input 模块
import { Component, OnInit ,Input } from '@angular/core';
3. 子组件中 @Input 接收父组件传过来的数据
export class HeaderComponent implements OnInit { @Input() msg:string constructor() { } ngOnInit() { } }
4. 子组件中使用父组件的数据
h2>这是头部组件--{{msg}}</h2>
注意:不要在app跟组件里演示,会报错
原文地址:https://www.cnblogs.com/loaderman/p/10899618.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。