Kartik Khandelwal Kartik Khandelwal - 4 months ago 296
AngularJS Question

Ionic State.go is not working

THIS IS MY LOGIN CONTROLLER

app.controller('lgctrl', function ($scope, $state) {
$scope.open = function () {
$state.go('home-menu');
}
});


THIS IS MY App.js

$stateProvider.state('login', {
url: '/login',
templateUrl: 'templates/login.html',
controller : 'lgctrl'
});

$stateProvider.state('app', {
url: '/app',
abstract: true,
templateUrl: 'templates/menu.html',
controller: 'AppCtrl'
});

$stateProvider.state('app.home-menu', {
url: '/home-menu',
views: {
'menuContent' :{
templateUrl: "templates/home-menu.html"
}
}
});


$urlRouterProvider.otherwise('/login');

THIS IS MY Login.html

<ion-view view-title="Login">
<ion-content>
<div class="list">
<label class="item item-input item-floating-label">
<span class="input-label">Email</span>
<input type="text" placeholder="Email">
</label>
<label class="item item-input item-floating-label">
<span class="input-label">Password</span>
<input type="Password" placeholder="Password">
</label>
</div>
<button ng-click="open()" class="button button-block button-positive">
Login
</button >
Don't have an Account? <a href = "#/signup">Sign-Up</a> | <a href="" >FAQ</a>
</ion-content>
</ion-view>


when i am clicking on login button i am getting this error my state.go is not redirecting to the home-menu page

Error: Could not resolve 'home-menu' from state 'login'
at Object.transitionTo (ionic.bundle.js:52013)
at Object.go (ionic.bundle.js:51946)
at Scope.$scope.open (Controller.js:38)
at fn (eval at compile (ionic.bundle.js:27638), <anonymous>:4:203)
at ionic.bundle.js:65427
at Scope.$eval (ionic.bundle.js:30395)
at Scope.$apply (ionic.bundle.js:30495)
at HTMLButtonElement.<anonymous> (ionic.bundle.js:65426)
at defaultHandlerWrapper (ionic.bundle.js:16787)
at HTMLButtonElement.eventHandler (ionic.bundle.js:16775)

Answer

In your route config, you've defined your state as 'app.home-menu', but try to access it as 'home-menu' in the controller. As such, ui-router can't find a matching state definition for 'home-menu'

Try $state.go('app.home-menu'); instead

Comments