angular子父传值 output 配合 EventEmitter使用

要将子组件中的参数发送给父组件;

1.## 子组件

@Output() deptClick = new EventEmitter<Department>();







 nzEvent(event: NzFormatEmitEvent): void {
     
    event.node.isSelected = true;
    const selectData = this.getSelectData();
    console.log(selectData);
    this.usertree();
    this.departName = selectData[0].origin.title;
    console.log(this.departName);
    this.deptClick.emit(selectData[0].origin.param as Department);
  }
 this.deptClick.emit(selectData[0].origin.param as Department);

使用deptClic.emit这个事件

在父组件中会出现deptClick这个事件 .event 是固定写法 里面是子组件抛过来的参数

<app-userdeparttree (deptClick)="setDept($event)" (closeHander)="confirm($event)"></app-userdeparttree>

你可能感兴趣的:(angular)