Reputation: 14290
I am trying to redirect my page to different page in my app.
The problem is that all the url settings are all in my app.js with ui-route
and I need the redirect happens inside my controller.
so app.js.
app.config(function($stateProvider) {
$stateProvider
.state('first', {
url: '/first',
templateUrl: 'first.html'
})
.state('second', {
url: '/second',
templateUrl: 'second.html'
})
})
my controller file
app.controller.('firstCtrl' , function(){
$scope.clickThis=function() {
//need to redirect to second page...
}
})
How do I redirect to different page inside my controller?
Upvotes: 0
Views: 65
Reputation: 2241
app.controller.('firstCtrl' ,["$scope", "$state", function($scope, $state){
$scope.clickThis=function() {
$state.go("second");
}
}]);
Upvotes: 2