gpt4 book ai didi

Angular [禁用] ="MyBoolean"不工作

转载 作者:太空狗 更新时间:2023-10-29 17:43:10 28 4
gpt4 key购买 nike

我有一些输入(复选框),如果我的 bool 值是真的,我希望它们被禁用。但它不工作......有趣的是提交按钮工作正常,那是相同的方法......

我的组件.html

          <form [formGroup]="BetreuungsoptionForm" (ngSubmit)="onSubmit()">
<label *ngIf="!eingetragen" for="art">Art</label>
<select *ngIf="!eingetragen" formControlName="art" id="art" class="form-control" [(ngModel)]="Art" required >
<option value="festeAnmeldung">feste Anmeldung</option>
<option value="flexibleAnmeldung">flexible Anmeldung</option>
</select>
<label for="datum">Beginn Datum</label>
<input formControlName="datum" type="date" id="datum" class="form-control" required>
<label *ngIf="(Art == 'festeAnmeldung')" for="montag">Montag</label>
<input *ngIf="(Art == 'festeAnmeldung')" formControlName="montag" [disabled]="montag" type="checkbox" id="montag" class="form-control wochentag">
<label *ngIf="(Art == 'festeAnmeldung')" for="dienstag">Dienstag</label>
<input *ngIf="(Art == 'festeAnmeldung')" formControlName="dienstag" [disabled]="dienstag" type="checkbox" id="dienstag" class="form-control wochentag">
<label *ngIf="(Art == 'festeAnmeldung')" for="mittwoch">Mittwoch</label>
<input *ngIf="(Art == 'festeAnmeldung')" formControlName="mittwoch" [disabled]="mittwoch" type="checkbox" id="mittwoch" class="form-control wochentag">
<label *ngIf="(Art == 'festeAnmeldung')" for="donnerstag">Donnerstag</label>
<input *ngIf="(Art == 'festeAnmeldung')" formControlName="donnerstag" [disabled]="donnerstag" type="checkbox" id="donnerstag" class="form-control wochentag">
<label *ngIf="(Art == 'festeAnmeldung')" for="freitag">Freitag</label>
<input *ngIf="(Art == 'festeAnmeldung' )" formControlName="freitag" [disabled]="freitag" type="checkbox" id="freitag" class="form-control wochentag">
<button type="submit" [disabled]="!BetreuungsoptionForm.valid" class ="btn btn-primary">Speichern</button>
<button type="button" (click)="OnBetreuungsoptionInfos()" class ="btn btn-success">weitere Informationen</button>
<button type="button" *ngIf="!gekuendigt" (click)="OnBetreuungsoptionLoeschen()" class ="btn btn-danger">Kündigen</button>
</form>

我的组件.ts

        this.BetreuungsoptionForm = new FormGroup
({
art: new FormControl(),
datum: new FormControl(this.BetreuungsoptionenKindRef[d].Beginn.toString().substring(0,10)),
montag: new FormControl(this.BetreuungsoptionenKindRef[d].Montag),
dienstag: new FormControl(this.BetreuungsoptionenKindRef[d].Dienstag),
mittwoch: new FormControl(this.BetreuungsoptionenKindRef[d].Mittwoch),
donnerstag: new FormControl(this.BetreuungsoptionenKindRef[d].Donnerstag),
freitag: new FormControl(this.BetreuungsoptionenKindRef[d].Freitag)
})
if(this.BetreuungsoptionenKindRef.Montag)
{
this.montag = true;
}
if(this.BetreuungsoptionenKindRef.Dienstag)
{
this.dienstag = true;
}
if(this.BetreuungsoptionenKindRef.Mittwoch)
{
this.mittwoch = true;
}
if(this.BetreuungsoptionenKindRef.Donnerstag)
{
this.donnerstag = true;
}
if(this.BetreuungsoptionenKindRef.Freitag)
{
this.freitag = true;
}

最佳答案

尝试 [attr.disabled]="freitag? true : null"[attr.readonly]="freitag"相反。

您可以使用像 [class.btn-lg]="someValue" 这样的属性以类似的方式。

您的文本框因此有效:

The disabled attribute is another peculiar example. A button'sdisabled property is false by default so the button is enabled. Whenyou add the disabled attribute, its presence alone initializes thebutton's disabled property to true so the button is disabled.

Adding and removing the disabled attribute disables and enables thebutton. The value of the attribute is irrelevant, which is why youcannot enable a button by writing <button disabled="false">Still Disabled</button>.

来自 https://angular.io/guide/template-syntax

关于Angular [禁用] ="MyBoolean"不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50130924/

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