Update controller data on factory data is changed Angular
My modal have 'SelectBankModelCtrl' as controller. 'SelectBankList' is my factory
Here when I SelectBankList.loadBankList() call from controller if loads data from server but not updating the data object on datagrid.
Controller: angular.module('sampleApp') .controller('SelectBankModelCtrl', function ($scope, $modalInstance, $log, items, SelectBankList) {
SelectBankList.loadBankList()
$scope.items = items;
$scope.selected = {
item: $scope.items[0]
};
$scope.ok = function () {
$modalInstance.close($scope.selected.item);
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
$scope.vm = {
bankList: SelectBankList.bankListdata,
bankListParams: SelectBankList.bankListParams,
pageSizeRangeOptions: SelectBankList.pageSizeRangeOptions,
pageSizeNumber: SelectBankList.pageSizeNumber
}
$scope.gridOptions =
{
data: 'vm.bankList',
columnDefs: [{field:'bankName', displayName:'Bank', enableCellEdit: false},
{field:'routingNumber', displayName:'Routing', enableCellEdit: false},
{field:'address', displayName:'Adderess', enableCellEdit: false},
{field:'city', displayName:'City', enableCellEdit: false},
{field:'state', displayName:'State', enableCellEdit: false},
{field:'zip', displayName:'Zip', enableCellEdit: false},
{field:'phone', displayName:'Phone', enableCellEdit: false}]
};
========================================================================== Service: angular.module('sampleApp') .factory('SelectBankList', function (Config, $window, $http, $log, transformRequestAsFormPost) { // Service logic // ...
var bankListdata = [{"bankId": '', "bankName": '1ST CITIZENS BK AND TR COMPANY INC', "routingNumber": "53202266", "address": "1314 PARK STREET", "city": 'COLUMBIA', "state":'SC', "zip":'29201'},
{"bankId": '', "bankName": '1ST CITIZENS BK AND TR COMPANY INC', "routingNumber": "53202266", "address": "1314 PARK STREET", "city": 'COLUMBIA', "state":'SC', "zip":'29201'},
{"bankId": '', "bankName": '1ST CITIZENS BK AND TR COMPANY INC', "routingNumber": "53202266", "address": "1314 PARK STREET", "city": 'COLUMBIA', "state":'SC', "zip":'29201'},
{"bankId": '', "bankName": '1ST CITIZENS BK AND TR COMPANY INC', "routingNumber": "53202266", "address": "1314 PARK STREET", "city": 'COLUMBIA', "state":'SC', "zip":'29201'},
{"bankId": '', "bankName": '1ST CITIZENS BK AND TR COMPANY INC', "routingNumber": "53202266", "address": "1314 PARK STREET", "city": 'COLUMBIA', "state":'SC', "zip":'29201'},
{"bankId": '', "bankName": '1ST CITIZENS BK AND TR COMPANY INC', "routingNumber": "53202266", "address": "1314 PARK STREET", "city": 'COLUMBIA', "state":'SC', "zip":'29201'}];
var pageSizeRangeOptions = [
{name: 20, value: 20},
{name: 50, value: 50},
{name: 100, value: 100}];
var pageSizeNumber = pageSizeRangeOptions[0];
var bankListParams = {
access_token: $window.localStorage['token'],
page:1,
pageSize: pageSizeNumber.value,
searchField: '',
sort: ''
}
// Public API here
return {
pageSizeRangeOptions: pageSizeRangeOptions,
pageSizeNumber: pageSizeNumber,
loadBankList : loadBankList,
bankListdata: bankListdata,
getBankList: function () {
return bankListdata;
},
getBankListParams: function () {
return bankListParams;
},
getPageSizeRangeOptions: function(){
return pageSizeRangeOptions;
},
getPageSizeNumber: function(){
return pageSizeNumber;
}
};
function loadBankList()
{
//$log.log("bankListParams.pageSize:" + bankListParams.pageSize);
var url = Config.getOAuthEndpoint() + '/bank/list';
return $http({
method: "GET",
transformRequest: transformRequestAsFormPost,
url : url,
params : bankListParams
}).then(handleBankListResult, handleBankListError);
}
function handleBankListResult (response){
if(response){
bankListdata = response.data.values;
$log.log("Upadated List:"+ response.data.values[0].bankName);
$log.log("Bank list: " + bankListdata[0].bankName);
}
}
function handleBankListError (response){
}
========================================================================= Markup:
Show records per page 链接地址: http://www.djcxy.com/p/13634.html上一篇: 路由器解析工厂未定义