Angular:ng-show和函数

jos*_*lvo 5 angularjs

假设您有一个类似的模板

<a ng-show=function()>a link</a>
Run Code Online (Sandbox Code Playgroud)

我的问题是:什么时候运行功能?如何判断角度是否该重新运行该功能?

sam*_*pel 3

嗯,ng-show 采用布尔值,因此使用它的最佳选择是在设置 ng-show 的逻辑中的某个位置调用函数。

$scope.show = false;

$scope.showSomething = function(myCondition){
    if(myCondition){
        myFunction();
        $scope.show = true;
    }
};
Run Code Online (Sandbox Code Playgroud)
<div ng-show='show'></div>
Run Code Online (Sandbox Code Playgroud)