1
我試圖綁定數據使用$資源的角度ng網格,但東西不工作 - 選項正在被應用到網格和指令是工作,我可以看到列標題,但沒有數據
服務/工廠
angular.module('app').factory('mvVegetableService',function($resource){
var myVegetableResource = $resource('/api/vegetable/:_id', {_id:"@id"}, {
update: {method:'PUT', isArray: false}
});
return myVegetableResource;
});
控制器
angular.module('app').controller('mvVegetableCtrl', function($scope, mvVegetableService){
$scope.vegetableService = mvVegetableService.query();
$scope.dataVegetables = {};
$scope.vegetableGridOptions = {
data: $scope.dataVegetables,
columnDefs:[{
field: "colorCode",
displayName: "Color Code"
}]
};
$scope.vegetableService.$promise.then(function(vegetables){
$scope.dataVegetables = vegetables;
console.log(vegetables);
// this outputs
// 0: Resource
// expanded
// $$hashKey: "00D"
// __v: 0
// _id: "xxxxxxxxxxxxxxxxxxxxxxxxxxx"
// colorCode: "GREEN"
// 1: Resource
// $promise: Object
// expanded
// catch: function (callback) {
// finally: function (callback) {
// then: function (callback, errback, progressback) {
// __proto__: Object
// $resolved: true
// length: 2
// $resolved: true
// length: 2
// __proto__: Array[0]
});
});
在同一頁/控制器我能夠NG-重複的選項在sele中CT元素,它工作正常。
嗯......這是所有正確的順序?爲什麼服務在ng-grid選項之後被調用? ... $ scope.dataVegetables = {}; $ scope.vegetableGridOptions = { data:$ scope.dataVegetables,...看起來像是將一個空對象作爲數據傳遞,並且之後將其填充。 –
這似乎是我見過這個網格綁定在其他職位的模式。只要變量存在(甚至爲空),我很確定它的順序是正確的 – maehue
您是否嘗試過沒有$ promise?或者說,返回的$ promise對象的內容是什麼? –