AngularJS从其他控制器更新$scope
AngularJS update $scope from other controller
我有以下问题:
在我的控制器中,我有这样的内容:
$scope.current = 0;
我有一些指令,它看起来像这样:
angular.module('myAPP')
.directive('post', function() {
return {
restrict: 'EA',
replace: true,
scope: {
post: '=',
index: '='
},
link: function(scope) {
//update the $scope.current here
},
templateUrl: 'components/blog/post.html'
};
});
有人能告诉我什么是最好的方法来做到这一点,它可以更新$作用域内的链接函数?
谢谢!
您的指令有一个隔离的scope
。
要从指令中更改current
,必须将其与指令作用域变量绑定,如下所示