我們有一個angular2組件,我們擁有某些單選按鈕。我在某些條件下檢查單選按鈕。單選按鈕在Angular 2中無法正常工作
單選按鈕的HTML代碼去爲:
<span class="radio-switch-group">
<label>
\t <input type="radio" name="radioView" id="All" (click)="onBtnClick('All')" [checked]="currentTab === 'All'">
\t <span class="radio-label">ALL Cars</span>
</label>
<label>
<input type="radio" name="radioView" id="Honda" (click)="onBtnClick('Honda')" [checked]="currentTab === 'Honda'">
<span class="radio-label">Honda</span>
</label>
</span>
TS文件如下:
export class CarComponent implements OnInit{
@Input() public currentTab: string = 'All';
public onBtnClick(carType: string){
this.currentTab = carType;
}
public ngOnInit() {
this.currentTab = 'All';
}
}
當我在標籤視圖實例化此組件從另一個組件單選按鈕不檢查即使當currentTab設置爲 '全部'
這個代碼是爲我工作得很好,請其他地方的複選框值清零 – sainu
我在實例化一個標籤這個組件檢查你的代碼,它不在這種情況下工作。 – hannah