$ state.go,数据未传递给视图

时间:2017-11-17 12:24:46

标签: html angularjs

我有一个帖子控制器应该使用$ state.go将响应数据发送到视图但似乎不起作用

我的控制器有帖子回复

 'use strict';


angular.module('App.addresses', [])

.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
  $stateProvider
  .state('addresses', {
    url: '/addresses',
    views: {
      'addressesContent': {
        templateUrl: "addresses/addresses.html",
        controller: 'AddressCtrl as address'
      }
    }
  })
}])


.controller('AddressCtrl', ['$state', '$http', '$scope', function($state, $http, $scope){
    this.search = function() {

        var data = {
             "mobile":$scope.mobile,
             "userId":localStorage.getItem('userId'),
             "sessionToken":localStorage.getItem('sessionToken')
            };
        $http({
            method: 'POST',
            url: url + '/getAddresses',
            data: data,
            headers: header
        })
        .then(function(response) {
                if (response.data.code == 101) {
                 var error = response.data.message;
                 $state.go('auth');
                }else {
                  var data = response.data;
                  console.log(data)
                  $state.go('display', {'addresses': data});
                }
        })         
    }
}])

这是我应该显示数据的视图代码

<table class="table">
    <thead>
        <tr>
            <th>Address Type</th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="addess in addresses">
            <td>{{address.addressType}}</td>
        </tr> 
    </tbody>
</table>

我做错了什么。被困在这一段时间了?

1 个答案:

答案 0 :(得分:0)

你需要将$ state.go改为州名,例如$ state.go(&#39;地址&#39;,{data:someStuff})你通常还要指定一个州将采用哪些参数/参数{{3 }}