我有这个工厂,
.factory('authentication',[function() { return { loginrequired: false }; }]);
我有这个控制器,
.controller('TopNavCtrl',['$scope','authentication',function($scope,authentication) { $scope.login = function() { authentication.loginrequired = true; }; }]);
link: function(scope,element,attrs) { scope.show = false; scope.$watch(authentication.loginrequired,function(value) { scope.show = value; }); }
当authentication.loginrequired = true时;是在控制器中完成的,范围.$watch中的指令未被调用.
有什么想法吗?