更新工厂数据的控制器数据更改为Angular
我的模式有'SelectBankModelCtrl'作为控制器。 'SelectBankList'是我的工厂
在这里,当我从控制器调用SelectBankList.loadBankList()时,如果从服务器加载数据但不更新数据网格上的数据对象。
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}]
};
================================================== ========================服务:angular.module('sampleApp').factory('SelectBankList',函数(Config,$ window,$ http ,$ log,transformRequestAsFormPost){//服务逻辑// ...
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){
}
================================================== =======================标记:
每页显示记录 链接地址: http://www.djcxy.com/p/13633.html上一篇: Update controller data on factory data is changed Angular