• Angular之输入输出属性


    一 父组件

    company.component.ts

    import { Component, OnInit } from '@angular/core';
    
    @Component({
      selector: 'app-company',
      templateUrl: './company.component.html',
      styleUrls: ['./company.component.css']
    })
    export class CompanyComponent implements OnInit {
    
      employee = 'Tom';
      skill: string;
    
      constructor() { }
    
      ngOnInit() {
      }
    
      releaseSkill(skill: string) {
        this.skill = skill;
      }
    
    }

    company.compnent.html

    <p>
      company works! {{skill}}
    </p>
    <app-employee [name]="employee" (releaseSkill)="releaseSkill($event);"></app-employee>

    二 子组件

    employee.component.ts

    import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
    
    @Component({
      selector: 'app-employee',
      templateUrl: './employee.component.html',
      styleUrls: ['./employee.component.css']
    })
    export class EmployeeComponent implements OnInit {
    
      @Input()
      name: string;
    
      skill: string;
    
      @Output()
      releaseSkill: EventEmitter<string> = new EventEmitter();
    
      constructor() { }
    
      ngOnInit() {
      }
    
      perform() {
        this.skill = '摄影';
        this.releaseSkill.emit(this.skill);
      }
    
    
    }

    employee.component.html

    <p>
      employee works! {{name}}
    </p>
    <button type="button" (click)="perform();">表演</button>

    三 运行效果

  • 相关阅读:
    Docker(二)Image 与网络
    Docker(一)概念与基础
    Apache Hudi 介绍与应用
    Flink读写Kafka
    Flink 应用的一致性保障
    Flink系统配置
    Flink架构(五)- 检查点,保存点,与状态恢复
    Flink架构(四)- 状态管理
    HBase 中读 HDFS 调优
    Nginx模块之http.md
  • 原文地址:https://www.cnblogs.com/sea-breeze/p/8955349.html
Copyright © 2020-2023  润新知