- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有多个 switch 语句,但对于某些情况,我需要常见的情况。所以,我正在尝试
OR 运算符 => ||
例子:
<ng-container [ngSwitch]="options">
<ng-container *ngSwitchCase="'a'">Code A</ng-container>
<ng-container *ngSwitchCase="'b'">Code B</ng-container>
<ng-container *ngSwitchCase="'c'">Code C</ng-container>
<ng-container *ngSwitchCase="'d' || 'e' || 'f'">Common Code</ng-container>
<ng-container *ngSwitchDefault>Code Default</ng-container>
</ng-container>
输出:
if case = 'd' returns Common Code
else if case = 'e' and 'f' returns the Code Default
这里倒数第二个案例由多个案例组成,现在默认情况下 case 'd'
仅适用于 case 'e' 和 'f'
>.
我在 ngSwitchCase
文档中看不到任何多个案例:
https://angular.io/docs/ts/latest/api/common/index/NgSwitchCase-directive.html https://angular.io/docs/ts/latest/api/common/index/NgSwitch-directive.html
Angular 2 不支持 ngSwitchCase
中的 ||
运算符吗?
最佳答案
如果你计算'd' || 'e' || 'f'
结果是 'd'
,当 options
不是 'd'
时,它不匹配。你不能那样使用 ngSwitchCase
。
这会起作用:
<ng-container [ngSwitch]="true">
<ng-container *ngSwitchCase="options === 'a'">Code A</ng-container>
<ng-container *ngSwitchCase="options === 'b'">Code B</ng-container>
<ng-container *ngSwitchCase="options === 'c'">Code C</ng-container>
<ng-container *ngSwitchCase="options === 'd' || options === 'e' || options === 'f'">Common Code</ng-container>
<ng-container *ngSwitchDefault>Code Default</ng-container>
</ng-container>
关于Angular 2 ngSwitchCase,或运算符不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43775796/
我正在观看 turtorial 并尝试做我学到的东西。我在下面收到错误。我不明白为什么我在浏览器控制台上显示此错误消息。它说 [ERROR ->]但我不知道为什么它说 ngSwitchCase 是错误
注释掉 ↓不返回错误 ↑ ─ ↓ ngSwitchCase 不支持负数吗? ? 错误如下: main.js?v1:23062 Un
我有多个 switch 语句,但对于某些情况,我需要常见的情况。所以,我正在尝试 OR 运算符 => || 例子: Code A Co
来 self 的代码中的示例。 tabs: object = [ { key: 'tab1', value: 'tab1' }, { key: 'tab2', value: 'tab2' },
使用以下 html: 如何在 ts 代码中获取对所选组件的引用?例如 public getChosenComponent(): MyComponentBas
我之前使用的是 ngSwitchWhen & 现在我想使用 ngSwitchCase,我引用了这里的语法 https://angular.io/docs/ts/latest/api/common/in
这个问题在这里已经有了答案: How to use ngSwitch in angular2 (3 个答案) 关闭 4 年前。 我正在尝试根据组件字段类型属性创建不同的 html 表格内容。我担心的
我在 .html 文件中显示了两个列表。我试图让我的代码不重复,所以我决定使用 ngSwitch,但我在做下一件事时遇到错误: ID:
我需要帮助... 当我使用 *ngIf 或 *ngSwitchCase View 时, View 会发生变化。自定义 javascript 函数在更改后不起作用。请帮助我解决这个问题。 最佳答案 Ng
我是一名优秀的程序员,十分优秀!