首页 > 其他 > 详细

angular父组件向子组件传值

时间:2019-11-29 18:40:40      阅读:158      评论:0      收藏:0      [点我收藏+]
// 调用子组件  向子组件传值和方法的方式
<app-header [title]="title" [run]="run"></app-header>

在子组件中,引入Input,通过@input() 方式引入,即可通过this.xxx使用

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

@Component({
  selector: ‘app-header‘,
  templateUrl: ‘./header.component.html‘,
  styleUrls: [‘./header.component.less‘]
})
export class HeaderComponent implements OnInit {
  constructor() { }
  @Input() title: any;
  @Input() run: any;
  ngOnInit() {
  }
  getPatrent() {
    this.run();
  }
}

 

angular父组件向子组件传值

原文:https://www.cnblogs.com/cazj/p/11959189.html

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