gpt4 book ai didi

javascript - Angular 4 : Radiobutton-value disappears after another radiobutton is checked

转载 作者:行者123 更新时间:2023-12-03 03:06:46 28 4
gpt4 key购买 nike

我有 3 个单选按钮,用于对 API 中的不同数据进行排序。在每个单选按钮上,如果我按另一个单选按钮,单选按钮值就会消失,如下所示: Thisthis. 。我尝试使用属性绑定(bind) [value],但这导致了错误。

TS:

  // Global inputvalues for Radiobuttons
@Input() all: string; image: string; video: string; true: boolean; false: boolean;


// Button-event payload
@Output() mediaButtonSelectionChange: EventEmitter<string> = new EventEmitter<string>();
@Output() licenseButtonSelectionChange: EventEmitter<string> = new EventEmitter<string>();
@Output() verifiedButtinSelectionChange: EventEmitter<string> = new EventEmitter<string>();

sortMedia() {
this.page = 0;
this.hitsArray = [];
this.mediaButtonSelectionChange.emit(this.mediaRadio);
this.mediaType = this.mediaRadio;
this.getStories(this.page, this.hits, this.feed, this.mediaType, this.query, this.verifiedType, this.licenseType, this.startDate, this.endDate);

}

(由于 API 调用,sortMedia() 函数对每个单选按钮排序都有一个)。

HTML:

<div class="container-fluid filter-btn">
<button class="btn btn-sm gay-flame-btn-light filter-btn dropdown-toggle" type="button dropdown-toggle" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">Media type
<span *ngIf="mediaType === 'all'" style="color:red;">(All)</span>
<span *ngIf="mediaType === 'image'" style="color:red;">(Images)</span>
<span *ngIf="mediaType === 'video'" style="color:red;">(Videos)</span>
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<div class="radio-group">
<div class="checkbox-forms gay-flame-forms form-group radio">
<label class="form-check-label">
<input type="radio" value='all' [(ngModel)]="mediaRadio" (change)="sortMedia()">
<i aria-hidden="true" [class.active-check]="'all' === 'all'" class="fa fa-circle"></i> All</label>
<label class="form-check-label">
<input type="radio" value="image" [(ngModel)]="mediaRadio" (change)="sortMedia()">
<i aria-hidden="true" class="fa fa-circle"></i> Images</label>
<label class="form-check-label">
<input type="radio" value="video" [(ngModel)]="mediaRadio" (change)="sortMedia()">
<i aria-hidden="true" class="fa fa-circle"></i> Videos</label>
</div>
</div>
</div>
</div>

(此部分对于每个单选按钮也有 3 个独立的部分)。

如果按下另一个按钮,如何保留每个单选按钮上的单选按钮值?

最佳答案

正如 @AnteJablan 提供的,解决方案只是(有点奇怪)向 HTML 添加一个 name 属性,如下所示:

<input type="radio" name="verification" value="false" [(ngModel)]="verifiedRadio" (change)="sortVerification()">

谢谢安特!

关于javascript - Angular 4 : Radiobutton-value disappears after another radiobutton is checked,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47134063/

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