Is it very bad to call a function that locally computes a value from an AngularJS expression?

前端 未结 2 1974
[愿得一人]
[愿得一人] 2021-01-23 15:05

I\'ve read an article on some AngularJS pitfalls using scopes, and it states that you should not use a function in expressions, and I understand that an expression may be evalua

2条回答
  •  鱼传尺愫
    2021-01-23 15:51

    One option is to set a $watch on the state condition. $watch can take a function parameter and so you can do this:

    $scope.$watch(function(){
        return $scope.prop1 && $scope.prop2 && $scope.prop3;        
    },function(val){
        $scope.state = val;
    });
    

    Here is a minimal demo

提交回复
热议问题