gpt4 book ai didi

angular - 如何在 Angular2+ 中点击重置按钮重置单选按钮?

转载 作者:行者123 更新时间:2023-12-02 16:37:25 24 4
gpt4 key购买 nike

我的 HTML 代码:

 <div class="dropdown-menu dropdown-menu-right filter-dropdown-menu  row">
<input type="radio" class="filter-dropdown-menu-padding" (click)="filter_source_type(0)" name="gender" value="male"> Admin
<input type="radio" class="filter-dropdown-menu-padding" (click)="filter_source_type(1)" name="gender" value="male"> Manager
<input type="radio" class="filter-dropdown-menu-padding" (click)="filter_source_type(2)" name="gender" value="male"> Member<br>

</div>

重置 HTML 代码:

<div class="btn btn-primary btn-reset" (click)="reset_filter()">Reset</div>

我的重置 ts 代码:

reset_filter() {
this.filter_source_type_value =null;
}

最佳答案

您可以使用ngModel通过分配值 null

来重置单选按钮

在 HTML 代码中执行此操作:

<div class="dropdown-menu dropdown-menu-right filter-dropdown-menu row">
<input type="radio" #radio class="filter-dropdown-menu-padding"
[(ngModel)]="gender" (click)="filter_source_type(0)" name="gender"
value="male"> Admin
<input type="radio" #radio class="filter-dropdown-menu-padding"
[(ngModel)]="gender" (click)="filter_source_type(1)" name="gender"
value="female"> Manager
<input type="radio" #radio class="filter-dropdown-menu-padding"
[(ngModel)]="gender" (click)="filter_source_type(2)" name="gender"
value="other"> Member
<br>
</div>
<div class="btn btn-primary btn-reset" (click)="reset_filter()">Reset</div>

在您的 .ts(组件)代码中执行此操作:

export class AppComponent {
gender = null; // Declared property with default `null` value

/**
* This function is used to reset radio buttons
*/
reset_filter() {
this.gender = null;
}
}

关于angular - 如何在 Angular2+ 中点击重置按钮重置单选按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49490733/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com