zoukankan      html  css  js  c++  java
  • 【Angular07】组件间通信

    父子组件

    @Input

    组件: 接收来自父组件的参数

    @ViewChild

    @ViewChild 属性装饰器,将子组件 CountdownTimerComponent 注入到私有属性 timerComponent 里面

    • import { AfterViewInit, ViewChild } from '@angular/core';
      import { Component }                from '@angular/core';
      import { CountdownTimerComponent }  from './countdown-timer.component';
      
      @Component({
        selector: 'app-countdown-parent-vc',
        template: `
        <h3>Countdown to Liftoff (via ViewChild)</h3>
        <button (click)="start()">Start</button>
        <button (click)="stop()">Stop</button>
        <div class="seconds">{{ seconds() }}</div>
        <app-countdown-timer></app-countdown-timer>
        `,
        styleUrls: ['../assets/demo.css']
      })
      export class CountdownViewChildParentComponent implements AfterViewInit {
      
        @ViewChild(CountdownTimerComponent)
       private timerComponent: CountdownTimerComponent;
      
        seconds() { return 0; }
      
        ngAfterViewInit() {
          setTimeout(() => this.seconds = () => this.timerComponent.seconds, 0);
        }
      
        start() { this.timerComponent.start(); }
        stop() { this.timerComponent.stop(); }
      }

    1

    1

    1

    1

    1

    1

    1

    兄弟组件

    11

    1

    1

    1

    1

    不相关组件

    11

    1

    1

    1

    1

  • 相关阅读:
    数据解压
    子区域数据合并
    数据压缩复制
    将Win10变回Win7/WinXP界面
    通过GP加载卫星云图-雷达图-降雨预报图
    Maven版本与JDK版本
    由输入法随想
    selinux开关
    android studio 配置
    NodeJS 笔记
  • 原文地址:https://www.cnblogs.com/tianxiaxuange/p/13685453.html
Copyright © 2011-2022 走看看