【问题标题】:event handler functions on mat radiomat radio 上的事件处理函数
【发布时间】:2021-03-15 05:07:03
【问题描述】:

我对单选按钮上的函数调用有点困惑

我正在调用 mat 收音机上的更改功能

第一种方法是我在 mat-radio-group 上只调用一个更改函数

<mat-radio-group aria-label="Select an option" formControlName="product_type" (change)="onProduct($event,i)">
    <mat-radio-button value="Plant">Plant and Related
    </mat-radio-button>&nbsp;&nbsp;
    <mat-radio-button value="Drugs">
        Drugs and Related</mat-radio-button>&nbsp;&nbsp;
    <mat-radio-button value="Others">Others
    </mat-radio-button>
</mat-radio-group>

第二种方法是我在单独的单选按钮上调用我的更改功能

<mat-radio-group aria-label="Select an option" formControlName="product_type">
    <mat-radio-button value="Plant" (change)="onPlant($event,i)">Plant and Related
    </mat-radio-button>&nbsp;&nbsp;
    <mat-radio-button value="Drugs" (change)="onDrugs($event,i)">
        Drugs and Related</mat-radio-button>&nbsp;&nbsp;
    <mat-radio-button value="Others" (change)="onOthers($event,i)">Others
    </mat-radio-button>
</mat-radio-group>

对我来说,如果我处理事件的逻辑相同但事实并非如此,那么这两种方式的行为应该相同。 第一种方式和第二种方式有什么区别??????

【问题讨论】:

    标签: javascript html angular angular-material radio


    【解决方案1】:

    调用你描述的这两种类型有区别, 您应该始终在 mat-radio-group 以便可以检测到单选按钮内部发生的任何更改,但如果您在 mat-radio-button 内部调用它,它将不起作用

    【讨论】:

    • 对我来说它在 mat-radio-button 内工作。我一路走来,但后来我的问题得到了解决。所以我怀疑它们之间有什么区别。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-20
    • 2020-12-01
    • 2019-05-27
    • 1970-01-01
    • 1970-01-01
    • 2020-05-29
    • 2020-12-11
    相关资源
    最近更新 更多