[英]passing url parameters in angular
我试图在视图之间传递一些url参数来获取特定用户的详细信息,但我发现很难做到这一点
下面是js和html
.controller('profile_detail_ctrl',['$scope','$http','$state',function($scope,$http,$state){
$http.get('http://localhost/myapp/app_ion/templates/profile/profile.php?profile_id='+$scope.profile_detail).success(function(data){
$scope.profile_detail=data;
$scope.profile_id=$state.params.profile_id;
});
//pass profile_id to view detail of a user bound to 'profile_detail_ctrl' controller
.state('tabs.detail',{
url:'/source/:profile_id',
views:{
'list-source':{
templateUrl: 'templates/profile/profile.html',
controller: 'profile_detail_ctrl'
}
}
})
的HTML
<ion-item href="#/tab/source/{{item.profile_id}}">
<div class="item item-avatar">
<img src="../usr_up_img/{{item.profile_pix}}">
<h2>{{item.name}}</h2>
<p>November 05, 1955</p>
</div>
</ion-item>
</ion-list>
</ion-content>
当用户单击链接"href"
。 它应该导航到包含用户详细信息的页面
据我可以从您的代码中推断出的那样,您在检索数据时犯了错误。 您需要发送来自$stateParams
profile_id,如下所示。
.controller('profile_detail_ctrl',['$scope','$http','$state','$stateParams',function($scope,$http,$state,$stateParams){
$http.get('http://localhost/myapp/app_ion/templates/profile/profile.php?profile_id='+$stateParams.profile_id).success(function(data){
console.log(JSON.stringify(data));
$scope.profile_detail=data;
});
尝试使用此代码
$http({
url: 'http://localhost/myapp/app_ion/templates/profile/profile.php',
method: "GET",
params: {profile_id: $state.params.profile_id}}).success(function (data) {
$scope.profile_detail=data;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.