Reputation: 552
I have tried to implement angular js $state.go() with parameter. But the $state.go() works fine without parameter. But with parameter it didn't works. I already tried many examples but no way. I need to display the parameter in html view. my state provider is,
$stateProvider
.state('home', {
url: '/',
views: {
'content@': {
templateUrl: 'content.html',
controller: 'dashCtrl'
}
},
params: {
obj: {
value:''
}
}
});
and controller is,
dashboard.controller('dashCtrl', function ($scope, $http, $state, $stateParams){
$state.go('dash_home', {obj: {value:'admin'}});
});
and my div is
<div>
<h1>welcome : {{value}} || {{obj.value}}</div>
what is the problem.?
Upvotes: 2
Views: 1415
Reputation: 552
I found my mistakes. The correct code is,
$stateProvider
.state('home', {
url: '/',
views: {
'content@': {
templateUrl: 'content.html',
controller: 'dashCtrl'
}
},
params: {
value:''
}
});
controller is,
dashboard.controller('mycontroller',function($scope, $http, $state, $stateParams){
$scope.user=$state.params.registerData;
$scope.redirect=function()
{
$state.params.registerData='mycontent';
$state.go('dash_home', {registerData:$state.params.registerData});
}
});
thanks all.
Upvotes: 2
Reputation: 5082
I guess you can't use objects in params. Just replace
params: {
obj: {
value:''
}
}
to this:
params: {
value:''
}
and also: $state.go('dash_home', {obj: {value:'admin'}});
to $state.go('home', {value:'admin'});
Upvotes: 1
Reputation: 30175
You cannot use parameters directly in the HTML. You first have to add it to the scope (or virtual model if you use that), e.g.
$scope.obj = $state.current.params.obj
And you have to do it in the controller of the state that you are going to of course, not in those where you call $state.go
Upvotes: 2