1

I would like to change the route of an angularjs application build with ionic framework, but the route didn't change

this is my code of app.js

angular.module('starter', ['ionic', 'starter.controllers'])
.state('app.annuaire.menuitempage', {
  url: "/menuitempage/:ID",
  views: {
    'menuContent' :{
      templateUrl: "templates/menuItemPage.html",
      controller: function($stateParams){
      $stateParams.ID  ;
     }
    }
  }
})

.state('app.annuaire', {
  url: "/annuaire",
  views: {
    'menuContent' :{
      templateUrl: "templates/annuaire.html",
      controller: 'MenuItemCtrl'
    }
  }
})   

And this is the code of my controller

  angular.module('starter.controllers', [])
  .controller('MenuItemCtrl', function($scope, $http, $location) {
    $scope.itemsMenu = {};

            var responsePromise =   $http.get("http://monguidepratique.com/mobile/getCategories.php?parent_id=0");

            responsePromise.success(function(data, status, headers, config) {
                //alert(data);
                $scope.itemsMenu = data;
            });
            responsePromise.error(function(data, status, headers, config) {
                alert("AJAX failed!");
            });
   $scope.itemClick = function(path){
            alert(1);
            $location.path(path); 

            };  

   }) 

And this is my html code in annuaire.html

 <div class="col"  ng-click="itemClick('/menuitempage/1628')"><img class="img_menu" src="img/home.png"><p class="titre_center">Accueil</p></div>

2 Answers 2

3

Try

$location.path(path)

instead of

$state.go(path)

You need to inject $location service into your controller.

Edit

If you are using $state.go - you should to use it next way:

$scope.itemClick = function(id){
  $state.go('app.annuaire.menuitempage', {'ID': id})
}; 

And HTML:

<div class="col"  ng-click="itemClick(1628)"><img class="img_menu" src="img/home.png"><p class="titre_center">Accueil</p></div>

The first param is state name, not URL, the second is an Object with your params.

Sign up to request clarification or add additional context in comments.

3 Comments

I tried this solution before, i have no errors now and the page didn't change
@tarekfellah: I updated my answer, you can take a look at it.
I edited my question, following your question to use $location.path(path) in stead of $state.go(path)
0

I solved my problem

in annuaire.html i changed

itemClick('/menuitempage/1628')

by

itemClick('/app/menuitempage/1628') 

and i changed the route name app.annuaire.menuitempage by

app.menuitempage 

.state('app.menuitempage', {
  url: "/menuitempage/:ID",
  views: {
    'menuContent' :{
      templateUrl: "templates/menuitempage.html",
      controller: 'SubMenuCtrl'
    }
  }
})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.