假设我有以下代码:
<div ng-if="Array.isArray(list)" ng-repeat="item in list">{{item}}</div>
<div ng-if="!Array.isArray(list)"> Not a list </div>
表达式始终计算为不是列表。为什么?
最佳答案
查看 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.
关于javascript - 复杂的 ng-if 表达式未执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22973956/