不能使用 Array.prototype.some/every 作为表达式
Cannot use Array.prototype.some/every as expression
假设我有一个数组 myArray
和一个按钮。
<button>Click</button>
我想使用 Array.prototype.some/every 禁用按钮,使用 ng-disabled 指令。例如:
<button ng-disabled="myArray.some(x => x == 1)">Click</button>
这会引发 Token '>' not a primary expression at column of the expression
。
为什么会这样?我做错了什么吗?
正如 AngularJS Developer Guide 所说,不能在 AngularJS 表达式中声明函数。
No Function Declarations: You cannot declare functions in an AngularJS expression, even inside ng-init directive.
假设我有一个数组 myArray
和一个按钮。
<button>Click</button>
我想使用 Array.prototype.some/every 禁用按钮,使用 ng-disabled 指令。例如:
<button ng-disabled="myArray.some(x => x == 1)">Click</button>
这会引发 Token '>' not a primary expression at column of the expression
。
为什么会这样?我做错了什么吗?
正如 AngularJS Developer Guide 所说,不能在 AngularJS 表达式中声明函数。
No Function Declarations: You cannot declare functions in an AngularJS expression, even inside ng-init directive.