Tell you a concept, the things in ng-if are called angular expressions, and angular will parse this expression. "x!='a'" is actually $scope.x != 'a'. By the way, this $scope is ng-repeat. "x!='a'"其实就是$scope.x != 'a',顺带一提这个$scope是ng-repeat产生的scope。 下面的test()当然会变parse成$scope.test()在ngRepeat的scope中没找到方法,所以从父scope中找到了你的方法, 然后你的方法return的是一个字符串, 所以判断永远是trueThe following test() will of course be parsed into $scope.test(). No method was found in the scope of ngRepeat, so you found your method from the parent scope. , then your method returns a string, so the judgment is always true.
Firstly, you did not pass x in, and secondly, what you returned was a string, and the string is always correct. Try writing it like this:
Tell you a concept, the things in ng-if are called angular expressions, and angular will parse this expression.
"x!='a'"
is actually$scope.x != 'a'
. By the way, this$scope
is ng-repeat."x!='a'"
其实就是$scope.x != 'a'
,顺带一提这个$scope
是ng-repeat
产生的scope。下面的
test()
当然会变parse成$scope.test()
在ngRepeat的scope中没找到方法,所以从父scope中找到了你的方法, 然后你的方法return的是一个字符串, 所以判断永远是true
The followingtest()
will of course be parsed into$scope.test()
. No method was found in the scope of ngRepeat, so you found your method from the parent scope. , then your method returns a string, so the judgment is alwaystrue
.