这是我的登录控制器
app.controller('lgctrl', function ($scope, $state) {
$scope.open = function () {
$state.go('home-menu');
}
});
这是我的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.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>
当我点击登录按钮时,我收到此错误,我的state.go未重定向到主菜单页面
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)
答案 0 :(得分:1)
在您的路线配置中,您已将状态定义为“app.home-menu”,但尝试将其作为控制器中的“主菜单”进行访问。因此,ui-router无法找到“home-menu”的匹配状态定义
尝试使用$state.go('app.home-menu');
答案 1 :(得分:0)
尝试更新以下代码。
$stateProvider
.state('login', {
url: '/login',
templateUrl: 'templates/login.html',
controller : 'lgctrl'
});
.state('app', {
url: '/app',
abstract: true,
templateUrl: 'templates/menu.html',
controller: 'AppCtrl'
});
.state('app.home-menu', {
url: '/home-menu',
views: {
'menuContent' :{
templateUrl: "templates/home-menu.html"
}
}
});
$urlRouterProvider.otherwise('/login');