【问题标题】:Angular - send checked state from child to parent componentAngular - 将检查状态从子组件发送到父组件
【发布时间】:2020-11-13 15:04:08
【问题描述】:

我在子组件中有一个复选框。我想将它的状态发送给父组件。在子组件中设置了这个事件发射器后,我在父组件中做什么?

子模板:

<mat-checkbox [(ngModel)]="isChecked" (change)="checkValue($event)"></mat-checkbox>

儿童 TS:

  @Output() onChecked: EventEmitter<any> = new EventEmitter<any>();

  public checkValue(isChecked: any): void {
    this.onChecked.emit(isChecked);
}

【问题讨论】:

    标签: angular


    【解决方案1】:

    你做了最困难的部分。之后你只需要听输出。

    parent.component.html

    <app-child (onChecked)="childOnChecked($event)"></app-child>
    

    parent.component.ts

    childOnChecked(isChecked: boolean) {
      // here your logic
    }
    

    【讨论】:

      猜你喜欢
      • 2020-07-25
      • 2018-07-07
      • 1970-01-01
      • 2020-04-04
      • 2019-10-24
      • 2021-02-15
      • 2020-05-31
      • 2018-08-12
      • 2019-08-22
      相关资源
      最近更新 更多