我试图根据复选框显示或隐藏按钮。以下是我的HTML代码:
<input class="form-check-input" [(ngModel)]="switchCase" type="checkbox" id="flexSwitchCheckChecked" (change)="toggleButton()"
<button class="btn btn-primary" *ngIf="!switchCase" [disabled]="!userform.valid">Button A</button>
<button class="btn btn-primary" *ngIf="switchCase" [disabled]="!userform.valid">Button B</button>
以下是我的TS代码:
toggleButton(){
console.log("Before : "+this.switchCase);
this.switchCase = !this.switchCase;
console.log("After : "+this.switchCase);
}
switchCase
更改的值根据复选框的值更改,并正确记录在控制台中。但是,按钮不会相应地切换,而我只能看到按钮A。我是新来的有角度的人,不确定我要去哪里哪里
.html代码
<input class="form-check-input" type="checkbox" id="flexSwitchCheckChecked"
(change)="toggleButton()">
<button class="btn btn-primary" *ngIf="!switchCase">Button
A</button>
<button class="btn btn-primary" *ngIf="switchCase">Button
B</button>
.ts代码
public switchCase: boolean = false;
toggleButton() {
this.switchCase = !this.switchCase;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句