tos*_*skv 1 javascript angularjs
如果在同一元素上有过滤器的ng-if和ng-repeat,则即使ng-if隐藏了元素,也会调用过滤器一次.
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope, $timeout) {
$timeout(function() {
$scope.list = [1, 2, 3, 4, 5, 6, 7, 8, 9];
}, 2000);
});
app.filter('crashyFilter', function() {
return function(list) {
return list.map(function(item) {
return item + 1;
});
};
});
Run Code Online (Sandbox Code Playgroud)
<body ng-controller="MainCtrl">
<div ng-if="list" ng-repeat="item in list | crashyFilter">
{{item}}
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
在浏览器控制台中,您可以看到地图调用失败一次,因为list参数未定义.我在这里做了一个龙头.
谁知道为什么会这样?
| 归档时间: |
|
| 查看次数: |
1878 次 |
| 最近记录: |