Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果值和函数之间存在差异,则angularjs ng_Angularjs_Angularjs Directive - Fatal编程技术网

如果值和函数之间存在差异,则angularjs ng

如果值和函数之间存在差异,则angularjs ng,angularjs,angularjs-directive,Angularjs,Angularjs Directive,使用有什么区别吗 ng如果使用值或函数 ng-if="myvalue" ng-if="myfunc()" 更新(为了更好地理解我为什么要求更新) html 如果我这样使用,我就得到了$digest()迭代次数 重新更新 (供钱德尔马尼评论) 对于角度,这两个表达式都是在当前范围的上下文中计算的表达式。Angular在每个摘要循环中都执行此操作 如果你使用的是功能性的方式,那么有更多的方式可以射中你的脚myfunc可以 $scope.myfunc=function() { //do som

使用有什么区别吗 ng如果使用值或函数

ng-if="myvalue"
ng-if="myfunc()"
更新(为了更好地理解我为什么要求更新)

html 如果我这样使用,我就得到了$digest()迭代次数

重新更新 (供钱德尔马尼评论)


对于角度,这两个表达式都是在当前范围的上下文中计算的
表达式。Angular在每个摘要循环中都执行此操作

如果你使用的是功能性的方式,那么有更多的方式可以射中你的脚<代码>myfunc
可以

$scope.myfunc=function() {
   //do some time consuming work
   return data;
};
在这种情况下,每个摘要周期上的绑定评估将使您的绑定和应用程序变慢


因此,如果您使用基于函数的绑定,请确保通过执行最小的处理来快速返回函数。

在ng repeat指令上调用函数可能会导致一些性能问题,但如果是一次性评估,那么就我所注意到的而言,这并没有什么区别


我总是尝试评估属性:
ng if=“myValue”
将评估范围变量
$scope.myValue

,感谢您的回复。我只是要求在我的脚本中使用func来触发$digest()迭代,但是func非常轻,就像nav.isLogged=function(){UserStorage.get();};请为函数
UserStorage.get()添加一些代码return angular.fromJson($sessionStorage.user)创建新对象时,与原始代码不匹配。远离函数或使用nav.isAuthenticated=function(){return UserStorage.get()!==null;};
function NavController($rootScope, UserStorage){
    var nav = this;
    nav.isAuthenticated = function() {
        UserStorage.get();
    }; 
}
function UserLoginController($rootScope,$state, Users, UserStorage) {
    var user = this;
    user.data = {};
        user.save = function() {
            Users.login(user.data).then(function(response) {
            console.log(response.data);
            UserStorage.set(response.data);
            $state.go('home');
        })
        .catch(function(response) {
            console.log(response);
            user.errors = response.data;
        });
    };
}
function UserStorage($sessionStorage) {
  return {
    set: function(data) {
        $sessionStorage.user = angular.toJson(data);
    },
    get: function() {
        return angular.fromJson($sessionStorage.user); 
    },
    del: function() {
        delete $sessionStorage.user;
    }
  };
}
$scope.myfunc=function() {
   //do some time consuming work
   return data;
};