Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
142
rated 0 times [  148] [ 6]  / answers: 1 / hits: 15393  / 10 Years ago, thu, october 23, 2014, 12:00:00

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>

More From » angularjs

 Answers
54

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.


[#69032] Tuesday, October 21, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
margaritakristinak

Total Points: 502
Total Questions: 127
Total Answers: 98

Location: England
Member since Mon, May 17, 2021
3 Years ago
;