neiza neiza - 5 months ago 14
AngularJS Question

passing url parameters in angular

I'm trying to pass some url parameter between view to get the detail of a particular user but i'm finding it hard to do

below is the js and 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>


When a user clicks on the link
"href"
. it should navigate to the page which contains the details of the user

Answer

As far as i can deduct from your code, you are making mistake in retrieving the data. You need to send your profile_id which comes from $stateParams as follows.

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