[英]How to perform property binding with disabled property in angular?
I was trying to print the names of only those cities for which the isDisabled value is true and the rest of the cities' values should be in a disabled state.我试图仅打印那些 isDisabled 值为 true 的城市的名称,并且城市值的 rest 应该在禁用的 state 中。 But I am getting errors as shown.
但是我收到了如图所示的错误。
The kind of output i want is:我想要的 output 是:
aaa, true啊,真的
bbb, false bbb,假的
ccc, false cc,假的
ddd, false ddd,假的
the first one should be highlighted and rest shoud be disabled.第一个应突出显示,rest 应禁用。
HTML file: HTML 文件:
<tr *ngFor="let x of cities;let i=index">
<td [disabled]="isDisabled[i]">
<tr>{{x.name}} , {{isDisabled[i]}}</tr>
</td>
.ts file: .ts 文件:
cities = [{ name: "aaa" }, { name: "bbb" }, { name: "ccc" }, { name: "ddd" }];
isDisabled=[true, false, false, false]
Template parse errors: Can't bind to 'disabled' since it isn't a known property of 'td'
模板解析错误:无法绑定到“已禁用”,因为它不是“td”的已知属性
You need some css code to solve your problem:您需要一些 css 代码来解决您的问题:
td.disabled {
font-weight: bold;
cursor: not-allowed;
}
Attaching this style to your code you can do the following:将此样式附加到您的代码中,您可以执行以下操作:
<tr *ngFor="let x of cities;let i=index">
<td [class.disabled]="isDisabled[i]">
{{x.name}}, {{isDisabled[i]}}
</td>
</tr>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.