javascript - 复杂的 ng-if 表达式未执行

标签 javascript angularjs

假设我有以下代码:

<div ng-if="Array.isArray(list)" ng-repeat="item in list">{{item}}</div>
<div ng-if="!Array.isArray(list)"> Not a list </div>

表达式始终计算为不是列表。为什么?

骗子:http://plnkr.co/edit/jlH0z3tLN6qbRowD5NGQ?p=preview

最佳答案

查看 Angular 文档:

Context

Angular does not use JavaScript's eval() to evaluate expressions. Instead Angular's $parse service processes these expressions.

Unlike JavaScript, where names default to global window properties, Angular expressions must use $window explicitly to refer to the global window object. For example, if you want to call alert() in an expression you must use $window.alert(). This restriction is intentional. It prevents accidental access to the global state – a common source of subtle bugs.

http://docs.angularjs.org/guide/expression

关于javascript - 复杂的 ng-if 表达式未执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22973956/

相关文章:

javascript - angularjs - ng-repeat 不会迭代 hashmap

javascript - 无法在 Angular js中创建动态行和树下拉列表

jquery - Angular JS 表单重新加载页面

javascript - 为什么它打印窗口对象而不是打印日期对象?

javascript - 使用 Javascript 使用 JSON 创建表

javascript - zustand next 13 在服务器上设置初始状态并在客户端上获取状态

javascript - 如何使用按键绑定(bind)和选定的文本建立链接

javascript - Angular-formly:为什么指令的行为与类型不同?

javascript - AngularJS - 通过 SSL 更改 API

javascript - AngularJS+Jasmine - 获取 Controller 范围写入指令