【发布时间】:2021-04-13 22:56:20
【问题描述】:
您能否指导我如何在 Angular 9 中使用*ngIf 处理多种情况,如下所示。以下不适用于我。
*ngIf="abc !! xyz"
但是,它适用于像
这样的个人情况*ngIf="abc"
或
*ngIf="xyz"
TS 码是:
radioButtonChanged($event){
let radioValue = event.target['value'];
console.log(radioValue);
if(radioValue =='abc'){
this.abc = true;
this.xyz = false;
} else{
this.abc=false;
this.xyz = true;
}
}
【问题讨论】:
-
*ngIf="abc || xyz" -
对更复杂的情况使用函数。
-
@HDJEMAI:在默认 CD 策略的情况下,将函数绑定到指令将在每个更改检测周期触发它。不推荐。
-
有些时候没有检测到变化,没用?
-
这能回答你的问题吗? angular 4: *ngIf with multiple conditions
标签: angular angular-forms angular-ng-if