淘先锋技术网

首页 1 2 3 4 5 6 7

子传父

  @Output() Name: EventEmitter<类型> = new EventEmitter();
  Start(){
 		 this.Name.emit(value)
 	 }
 	 父组件接收
 	 <app-child  (Name)=Name($event)></app-child>
 	 Name(event:类型){
		console.log(event);
	}

父传子

1.@input value:string
	value:string
<app-child  [value]=value></app-child>
在ngOnChanges中接受并检测其变化
 ngOnChanges(changes: SimpleChanges): void {
 console.log(changes['value']);
}
2.@input value: Subject<string> 
	value: Subject<string> = new Subject();
<app-child  [value]=value></app-child>
传:this.value.next(value);
收:  this.changing.subscribe((v: string) => {
 		 console.log(v);
    });