如何在 angular 条件下禁用复选框?
How to make checkbox disabled on condition in angular?
以前我使用布尔值 属性 禁用复选框。
这是我到目前为止尝试过的方法。
app.component.ts
---------------
ReadOnly: boolean;
ngOnInit() {
this.ReadOnly = true;
}
app.component.htmt
------------------
<input type="checkbox" [disabled]="ReadOnly">
{
"id":1,
"category":"cc",
"sortOrder":"1",
"active":"Y",
"Products":[
{
"id":100,
"backEndName":"DDA",
"sortOrder":"1",
"active":"N"
}
]
}
现在我需要使用活动条件使字段禁用。我该怎么做?
这样试试:
<input type="checkbox" [disabled]="item.active == 'N'">
import {Renderer2} from '@angular/core';
constructor( public htmlManipulator: Renderer2) {}
radioButton(e) {
if (e.target.checked) {
this.htmlManipulator.setProperty(this.emilId.nativeElement, 'disabled', null);
} else {
this.htmlManipulator.setProperty(this.emilId.nativeElement, 'disabled', ' ');
console.log('phone click');
}
}
<input type="radio" value="email" name="group2" (change)="radioButton($event)">Email Id
以前我使用布尔值 属性 禁用复选框。
这是我到目前为止尝试过的方法。
app.component.ts
---------------
ReadOnly: boolean;
ngOnInit() {
this.ReadOnly = true;
}
app.component.htmt
------------------
<input type="checkbox" [disabled]="ReadOnly">
{
"id":1,
"category":"cc",
"sortOrder":"1",
"active":"Y",
"Products":[
{
"id":100,
"backEndName":"DDA",
"sortOrder":"1",
"active":"N"
}
]
}
现在我需要使用活动条件使字段禁用。我该怎么做?
这样试试:
<input type="checkbox" [disabled]="item.active == 'N'">
import {Renderer2} from '@angular/core';
constructor( public htmlManipulator: Renderer2) {}
radioButton(e) {
if (e.target.checked) {
this.htmlManipulator.setProperty(this.emilId.nativeElement, 'disabled', null);
} else {
this.htmlManipulator.setProperty(this.emilId.nativeElement, 'disabled', ' ');
console.log('phone click');
}
}
<input type="radio" value="email" name="group2" (change)="radioButton($event)">Email Id