1
我的服務:AngularJS不具約束力的承諾,模板
這是2個原因我的錯誤的錯誤1:
getAll: function(url) {
deferred.resolve($http({ <--- deferred.resolve should not have been here
method: 'GET',
url: url,
contentType: "application/json; charset=utf-8",
cache: true,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}));
return deferred.promise;
},
本來應該改爲:
getAll: function (url) {
$http({
method: 'GET',
url: url,
contentType: "application/json; charset=utf-8",
cache: true,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).success(function (data) {
deferred.resolve(data);
});
return deferred.promise;
我的控制器:
這是2個原因我的錯誤的錯誤2:
// $scope.PassengerVehicles = crudSvc.getAll('/_json/PassengerVehicles.js');
// should have been:
crudSvc.getAll('/_json/PassengerVehicles.js').then(function (data) {
$scope.PassengerVehicles = data;
});
我的模板:
<ul data-ng-repeat="passVeh in PassengerVehicles">
<li>{{passVeh.itemId}}</li>
</ul>
這裏是我的搶劫者,這一直是相關的反恐執行局:
AngularJS not binding promise to template
比你四!
我將服務更改爲您的服務。我的控制器方法調用看起來和你的完全一樣,控制檯輸出和以前一樣,我仍然沒有綁定到模板。 –
你有沒有改變你的控制器看起來像我的,因爲它之前沒有。調試服務調用以確保其返回承諾並調試控制器以確保調用「then」函數。 – Fourth
下面是我的翻譯:http://plnkr.co/edit/QJlkMjh0MkXSRJGk7oJV?p=preview –