Tom*_*ock 8 javascript angularjs
我是棱角分明的新手,一直在寻找答案,为什么这不起作用.
我的指示在这里:
.directive('carrouselPreview', function () {
return function (scope, element, attrs) {
scope.$watch(scope.carouselPreview, function () {
alert('changed');
}, true);
}
});
Run Code Online (Sandbox Code Playgroud)
这会监视对scope.carouselPreview的更改,该更改通过以下函数进行更改:
$scope.showPreview = function(ind){
$scope.carouselPreview = ind;
}
Run Code Online (Sandbox Code Playgroud)
这个函数肯定会触发并更改scope.carouselPreview - 但是watch函数永远不会触发!
我意识到我可能在这里愚蠢,但我看了一遍,看起来很好.
如果今晚有人帮我解决这个问题,我会永远爱你!
dnc*_*253 13
进入的第一个参数$watch是一个字符串(在范围的上下文中计算)或一个函数.所以你想要的是:
scope.$watch("carouselPreview", function () {
alert('changed');
}, true);
Run Code Online (Sandbox Code Playgroud)
见http://docs.angularjs.org/api/ng.$rootScope.Scope#$watch
| 归档时间: |
|
| 查看次数: |
6543 次 |
| 最近记录: |