使用Web服务将新项目添加到列表后,iOnic列表不会刷新

时间:2016-10-13 10:46:54

标签: list ionic-framework

我们有一个基于iOnic的项目,在结账时,用户可以在其帐户中添加新地址。 enter image description here

这是我的控制器文件的样子

$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();
                });
        };

这就是我的服务文件的样子

    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);
        };

    }]);


})();

当我添加新地址时,它会添加到数据库中,但不会显示在列表中。我尝试添加$ scope.refreshList();代码也。当我退出并返回时,它确实显示出来。感谢您的帮助

查看代码

<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>

0 个答案:

没有答案