我無法獲取UI上更新的數量,但是當我查看網絡時,我能夠看到響應值。我的代碼有什麼問題,我不熟悉$ resource和angularjs的新特性。
<ion-view title="HSF" id="page4">
<ion-content overflow-scroll="true" padding="true" class="has-header">
<h3 id="hSF-heading5" style="color:#000000;text-align:center;">Summary</h3>
<ion-scroll>
<ul class="list" data-ng-repeat="mth in monthList()">
<li class="item item-positive" ng-click="">
{{mth.label}}
<span style="float: right;">Total: ${{mth.amount}}</span>
</li>
</ul>
</ion-scroll>
</ion-content>
</ion-view>
.factory('RESTService',['$resource', function($resource){
return $resource('http://xxx/' + 'transaction', {id: '@id'},{
readSales: {
method: 'POST',
isArray: false
}
});
}])
.controller('HSFCtrl', function($scope, $http, $state, RESTService) {
//region YearlySales
var list = [];
var today = new Date();
var yearIndex = today.getFullYear();
var yearObj = {
label: "",
amount:0
};
yearObj.label = yearIndex;
$http({
url: 'http://xxx/' + 'transaction',
data: {"type": 3, "datetime": yearObj.label},
method: 'POST'
}).success(function (response) {
yearObj.amount = response;
});
list.push(yearObj);
$scope.yearList = list;
//endregion
//region MonthlySales
$scope.monthList = [];
var months = [1,2,3,4,5,6,7,8,9,10,11,12,13];
var monthNames = [ 'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December' ];
for(var mth in months){
$scope.amount = {};
var monthObj = {
label: "",
amount: 0
};
var objToSend = {
type: 2,
datetime: '2016' + '-' + mth
};
//console.log(mth);
var read = RESTService.readSales(objToSend);
read.$promise.then(function(result){
monthObj.amount = Number(result);
});
monthObj.label = monthNames[mth];
$scope.monthList.push(monthObj);
}
//console.log($scope.monthList);
//endregion
$scope.goToMSP = function(){
$state.go('tabsController.MSP');
}
});