I am trying to pass parameters via the ui-router state.go
However, I am not sure how to pass the parameters. Here are my codes
app.config(function($stateProvider) {
$stateProvider
.state('first', {
url: '/first',
templateUrl: 'first.html'
})
.state('second', {
url: '/second',
templateUrl: 'second.html'
})
})
//my first.html
app.controller.('firstCtrl' ,["$scope", "$state", function($scope, $state){
$scope.userInput <- come from user
$scope.clickThis=function() {
$state.go("second", $scope.userInput);
}
}]);
//my second.html
app.controller.('secondCtrl,["$scope", "$state", function($scope, $state){
//How do I get the parameter that is passed to here..
})
I can redirect the page to second.html but I can't seem to get the parameter that is passed to my secondCtrl. Can anyone help me about it?
Thanks.
You could do this way in the first controller:-
In the second controller inject $stateParams service.
and register that in your state:
First you have to add parameter in route.
Now add in first controller
In second controller inject $stateParams
Instead of adding additional param in the url, you could do it on the other way.
All other changes would be same with what other answers.