当前位置: 动力学知识库 > 问答 > 编程问答 >

iOnic list not refreshing after adding a new item to the list using web service

问题描述:

We have a iOnic based project and during check out users can add new address to their account.

This is what my controller file look like

$scope.addAddress = function() {

$scope.showLoading();

addressService.addUserAddress($scope.userDetails.userID, $scope.addAddressdata.houseNo, $scope.addAddressdata.street, $scope.addAddressdata.AddDesc, $scope.addAddressdata.LID)

.success(function(response) {

console.log(response);

$scope.hideLoading();

$scope.closeModal();

$scope.getAllAddress();

});

};

$scope.getAllAddress = function() {

addressService.getAllLocations()

.success(function(response) {

$scope.locations = response;

$scope.hideLoading();

});

};

And this is what my services file look like

 function() {

"use strict";

var myApp = angular.module('jobolo');

myApp.service('addressService', ['$http', 'appVariableService', function($http, appVariableService) {

var addressService = this;

addressService.getAllLocations = function() {

var data = {

appid: appVariableService.get('appId')

};

return $http.post(appVariableService.get('baseURL') + 'useraddress/getMyLocation', data);

};

addressService.getUserAddress = function(userId) {

return $http.get(appVariableService.get('baseURL') + 'useraddress/myaddress/' + userId, {cache:false});

};

addressService.addUserAddress = function(userId, houseNo, street, adddesc, lid) {

var data = {

appid: appVariableService.get('appId'),

userid: userId,

houseno: houseNo,

street: street,

adddesc: adddesc,

lid: lid,

};

return $http.post(appVariableService.get('baseURL') + 'useraddress/adAdd' , data);

};

}]);

})();

When I add a new address it does add to the database but isn't showing in list. I tried adding $scope.refreshList(); to the code too. When I log out and come back it does show up. Thank you for your help in advance

View Codes are

<ion-view class="main-content">

<ion-nav-buttons side="secondary">

<button menu-toggle="right" class="button button-icon icon ion-navicon"></button>

</ion-nav-buttons>

<div class="bar bar-subheader">

<h2 class="title">Select Address</h2>

</div>

<ion-content class="has-subheader" scroll="true" overflow-scroll="true" style="bottom:57px">

<div class="list">

<ion-radio

ng-model="data.selectedAddress"

ng-value="address"

ng-repeat="address in userAddresses"

class="radio-nowrap"

>

House No. {{address.HouseNo}}, {{address.Street}}, {{address.AddDesc}}, {{address.AreaName}}, {{address.City}}

</ion-radio>

</div>

<!-- <div class="row">

<div class="col location-form">

<button class="button" type="button" ng-click="openModal()">Add New Address</button>

</div>

</div> -->

</ion-content>

<div class="row" style="position: absolute;bottom: 0;padding:0">

<div class="col location-form">

<button class="button" type="button" ng-click="openModal()">Add New Address</button>

</div>

<div class="col location-form">

<button class="button" type="button" ng-disabled="!data.selectedAddress" ng-click="selectAddress(data.selectedAddress)">Select Address</button>

</div>

</div>

分享给朋友:
您可能感兴趣的文章:
随机阅读: