0
處理angularjs中的pager指令。當我硬編碼示例收集($ scope.installations)一切正常,但是當我從服務器的'選項'屬性拉指令的數據總是'未定義'。Angularjs指令解析控制器集合
這裏是我的指令:
angular.module("qusion.ui.pager", [])
.directive("qnPager", [
function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
var options = scope.$eval(attrs.qnPager);
var settings = {
source: null,
paging: null,
schema: {
page: 'PageNumber',
size: 'Size',
totalPages: 'TotalPages',
totalCount: 'TotalCount'
}
};
angular.extend(settings, options);
scope.$watch(settings.source, function(value) {
console.log(settings.source); // UNDEFINED ???
});
}
};
}
]);
這裏是我如何調用它。
<ul qn:pager="{source: installations}">
最後我控制器樣品
function MyController(Installation){
$scope.installations = [];
// get sample (this works)
// $scope.installations = [{ID: 1, Title: 'Test 1'}, {ID: 2, Title: 'Test 2'}]
// get from server (this don't work)
Installation.getAll().then(function(data) {
$scope.installations = data.Installations;
});
}
你能分享你'安裝'的服務代碼嗎? – wajatimur
還有更多的依賴關係,所以它會有很多代碼粘貼在這裏。這只是http請求返回的承諾。這部分工作正常,因爲模板中的表格填充了安裝數據。 –
您使用異步或同步請求填寫的數據? – wajatimur