// 泛型:任意类型
class Person<T>{
emit(msg:T){
console.log(msg);
}
}
var p = new Person<string>();
p.emit("hello world")
2-1 子组件引入Output和EventEmitter
import { Component, OnInit,Input,Output,EventEmitter } from '@angular/core';
2-2 子组件中实例化EventEmitter
@Output() private outer = new EventEmitter<string>();
2-3 子组件中通过EventEmitter实例化的对象outer,广播数据
handleClick(){
this.outer.emit("101001");
}
<button (click)="handleClick()">向父传参</button>
2-4 父组件中接收事件
<app-header (outer)="getId($event)"></app-header>
export class AppComponent {
getId(id:string){
console.log(id);
}
}