【发布时间】:2015-09-26 01:55:47
【问题描述】:
我调用了一个返回 JSON 响应的 web 服务。我想使用 ng-repeat 绑定这个 json 数据以查看。 我在两个屏幕上使用相同的控制器。
流程是这样的:
- 我调用 Web 服务并获取 json。
- 我使用 $state.go('screen2') 移动到另一个屏幕
- 在这里我尝试将我的 json 与我的 html 绑定。
我的代码:
angular.module('controller').controller('Ctrl1', function($scope, $state, $http) {
$scope.myList;
$scope.getUserList = function() {
$http({
method: 'GET',
url: someurl,
}).then(function(response) {
//success
if (response.data.status == "OK") {
$scope.myList = response.data.data;
$state.go('screen2');
}
}, function(response) {
alert('failed');
});
}
我的视图(screen2):
<ion-view view-title="Select User">
<ion-header-bar class="bar-user">
<h1 class="title">Select User</h1>
</ion-header-bar>
<ion-content class="padding">
<div class="mainWrap">
<div class="text-title">
Lorel ipsum
</div>
<div class="list user">
<a class="item item-icon-left" href="#" ng-repeat="v in myList">
<i class="icon ion-wifi"></i>
{{v.name}}
</a>
</div>
</ion-content>
</ion-view>
当我 hardcode 并将该 json 数据直接附加到控制器的范围时。一切正常。但是当我在 $http 的响应中绑定相同的 json 时,没有任何效果。
网络服务响应:
{
"status": "OK",
"data": [
{
"name": "lorel",
"type": "off"
},
{
"name": "edimax",
"type": "on"
},
{
"name": "ipsum",
"type": "on"
},
{
"name": "blah blah",
"type": "on"
}
]
}
【问题讨论】:
标签: angularjs angularjs-scope ionic-framework angularjs-ng-repeat ng-repeat