Go to a specific page in ionic framework


#1

Im stuck in a problem that i have to open a specific page in ionic framework using the controller. I have to go to the following page

#/tab/hotel_details/1

when i click ok button in the ionic popup window

 $scope.showAlert = function() {
   var alertPopup = $ionicPopup.alert({
     title: 'Click OK for further details',
   });
   alertPopup.then(function(res) {
   //Go to a specific page
   });
 };

I cant use $state.go("tab.hotel_details"); , because i have to go to hotel_details/1 .
I have to get rid of the above problem for further development of my app.


#2

Set your state as the following:

.state('tab.hoteldetails', {
  url: '/hotel_details/:id',
    views: {
      'hotel': {
        templateUrl: '/path/to/hoteldetails.html' },
        controller: 'hoteldetailsCtrl'
      }
    }
  })

In your controller you then simply do the following:

$scope.myFunction = function(objectID){
  state.go('tab.hoteldetails', {"id": objectID});
}

Then call the function in your view on a onClick event:

<button ng-click="myFunction(item.id)">View details</button>

You can now retrieve your objectID in your hoteldetailsCtrl with the $stateParams service.

Please read up on nested states and views in the ui-router documentation here: