angular - 如何在角度的ngIf中使用OR条件?
问题描述
假设我在 component.ts 中有逻辑:
selectInput(event) {
let selected = event.target.value;
if (selected == "firm") {
this.isNameSelected = true;
} else if(selected == "consignment") {
this.isNameSelected = false;
this.labelForCP=true;
}
else{
this.tash=true;
this.isNameSelected = false;
this.labelForCP=false;
}
}
在我的 html 中,我有:
<div class="form-group col-md-4" *ngIf="!isNameSelected">
我试图结合*ngIf="!isNameSelected || tash"
,但我在控制台中收到错误,因为我无法应用这种方法。true(OR condition)
如果条件中的任何一个必须进入该部分,我想要条件。
解决方案
ngIf 的工作方式与普通 If 条件的工作方式几乎相同。下面是一个例子。
<div class="form-group col-md-4" *ngIf="!condition1 || condition2">
推荐阅读
- angular - 如何在 innerHTML 中使用 Angular 切片管道?
- mysql - 如何将随机数的参数传递给程序mysql?
- node.js - 如何在 node.js 中读取具有嵌套类别的 json 文件
- django - 以字符串形式显示 ISO 日期值
- javascript - 我想使用 fetch 方法从 api url 获取请求。但我不断收到错误 400
- kubernetes - 访问 ArgoCD 服务器
- exception - 对“吃异常”(在 Java 中)感到困惑?
- react-native - react-native 如何在删除平面列表中的项目时刷新
- azure - Msal-Angular v1-acquireTokenPopup/LoginPopup 返回一个权限不足的访问令牌,即使在授予管理员同意后也是如此
- c# - .NET Core 3.1 项目的 SonarQube 分析失败