我只是从我的API获取信息,它反应良好。
console.log(response)
将输出,
Object {id: 1, username: "testmd", first_name: "Juan",
last_name: "Dela Cruz", type: "Pediatrician"…}
控制器
vm.getDoctor = function(id) {
$http.get(CONSTANTS.LINK+'/doctors/'+id).success(function(response) {
vm.thisDoctor = {
name : response.first_name + ' ' + response.last_name,
address : response.clinical_address,
};
console.log(vm.thisDoctor.address);
$state.go('tabs.doctor');
});
}
现在我在我的视图中访问 vm.thisDoctor doctor-this.html
<a class="item item-thumbnail-left">
<img src="cover.jpg">
<h2>{{ appt.thisDoctor.name }}</h2>
<p>{{appt.thisDoctor.address}}</p>
</a>
这是我的app.js
.state('tabs.doctor', {
url: '/doctor/{doctorId}',
views: {
'tab-appts': {
templateUrl: 'templates/appts/doctors-this.html',
controller: 'ApptsCtrl as appt'
}
}
})
我的code
错了吗?我已经工作了几个小时了。
答案 0 :(得分:2)
从服务器获得响应后,您正在使用s = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)
更改视图,这就是您丢失数据的原因。相反,您可以将对象传递给状态并将其分配给控制器范围,如下所示。
<强> JS1 强>
$state.go
<强> JS2 强>
vm.getDoctor = function(id) {
$http.get(CONSTANTS.LINK+'/doctors/'+id).success(function(response) {
vm.thisDoctor = {
name : response.first_name + ' ' + response.last_name,
address : response.clinical_address,
};
console.log(vm.thisDoctor.address);
$state.go('tabs.doctor', {
args: {
data: vm.thisDoctor
}
});
});
}
ApptsCtrl (注入.state('tabs.doctor', {
url: '/doctor/{doctorId}',
views: {
'tab-appts': {
templateUrl: 'templates/appts/doctors-this.html',
controller: 'ApptsCtrl as appt'
}
},
params: { args: {} } // Need to add this
})
)
$stateParams