[英]ng-click change route in angularjs with param
I would like to change the route of an angularjs application build with ionic framework, but the route didn't change 我想用离子框架改变angularjs应用程序构建的路径,但路线没有改变
this is my code of app.js 这是我的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 这是我在annuaire.html中的html代码
<div class="col" ng-click="itemClick('/menuitempage/1628')"><img class="img_menu" src="img/home.png"><p class="titre_center">Accueil</p></div>
Try 尝试
$location.path(path)
instead of 代替
$state.go(path)
You need to inject $location
service into your controller. 您需要将
$location
服务注入您的控制器。
If you are using $state.go
- you should to use it next way: 如果您使用
$state.go
- 您应该使用下一个方法:
$scope.itemClick = function(id){
$state.go('app.annuaire.menuitempage', {'ID': id})
};
And HTML: 和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. 第一个参数是状态名称,而不是URL,第二个参数是带有参数的对象。
I solved my problem 我解决了我的问题
in annuaire.html i changed 在annuaire.html我改变了
itemClick('/menuitempage/1628')
by 通过
itemClick('/app/menuitempage/1628')
and i changed the route name app.annuaire.menuitempage by 我更改了路线名称app.annuaire.menuitempage
app.menuitempage
.state('app.menuitempage', {
url: "/menuitempage/:ID",
views: {
'menuContent' :{
templateUrl: "templates/menuitempage.html",
controller: 'SubMenuCtrl'
}
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.