我正在尝试创建一个简单的轮播。源图像通过$resource
获得。我需要一种表达方式来通知数据已经改变。我需要使用包含在ng-model属性中的数组中的第一张照片初始化图库。
代码:
app.directive('ngCarousel', function() {
var template = //...;
return {
restrict: 'E',
require: 'ngModel',
scope: {data:'='},
compile:function(tElement, tAttrs, transclude) {
tElement.html(template);
//...
return function(scope, element, attrs, ctrl) {
//...
attrs.$watch(scope.$modelValue, function() {
//initialize the template
})
}
}
}
});
答案 0 :(得分:0)
我需要一种通知数据已发生变化的监视表达式。
向$ resource查询添加回调。即,而不是(我在这里猜测,因为你没有提供任何显示你如何使用$ resource的代码)
$scope.image1 = MyResourceWrapper.query()
改为:
MyResourceWrapper.query( function(data) {
// Now you know the data has arrived. Initialize your gallery, etc.
...
}