gpt4 book ai didi

javascript - AngularJs:双重检查 ng-show

转载 作者:行者123 更新时间:2023-11-28 20:14:48 25 4
gpt4 key购买 nike

为什么像 ng-show(或其他)这样的指令中的任何表达式的检查都是重复的?我做了简单的jsfiddle示例http://jsfiddle.net/fA5YX/ 。在浏览器控制台中查看。

<div ng-app ng-controller="ctrl" ng-show="test()">shown</div>
<script>
function ctrl($scope) {
$scope.test = function() {
console.log('check');
return true;
}
}
</script>

如何让它停止?我只需要一张支票。

最佳答案

可能链接到Controller function getting called twice using ng-show - 引用:

At each digest cycle, for every watch, AngularJS evaluates the associated expression to see if there's any change and if there is, invoking the listener (in the case of ng-show/ng-hide, the listener will show or hide the element based on the value returned by ready()).

关于javascript - AngularJs:双重检查 ng-show,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19348406/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com