我的程式碼是這樣的:
$scope.toCreate = function () {
console.log('create')
$state.go('createAccount')
}
$stateProvider.state('login', {
url:'/login',
templateUrl:'js/pages/login.html',
controller:'loginCtrl'
}).state('createAccout', {
url:'/createAccount',
templateUrl:'js/pages/createAccount.html',
controller:'createAccountCtrl'
})
瀏覽器控制台報錯如下:
Error: Could not resolve 'createAccount' from state 'login'
at Object.transitionTo (http://localhost:63342/atMoon/www/lib/ionic/js/ionic.bundle.js:33795:39)
at Object.go (http://localhost:63342/atMoon/www/lib/ionic/js/ionic.bundle.js:33678:19)
at Scope.$scope.toCreate (http://localhost:63342/atMoon/www/js/controllers/loginCtrl.js:8:17)
at http://localhost:63342/atMoon/www/lib/ionic/js/ionic.bundle.js:18520:21
at http://localhost:63342/atMoon/www/lib/ionic/js/ionic.bundle.js:42067:9
at Scope.$eval (http://localhost:63342/atMoon/www/lib/ionic/js/ionic.bundle.js:20382:28)
at Scope.$apply (http://localhost:63342/atMoon/www/lib/ionic/js/ionic.bundle.js:20480:23)
at HTMLButtonElement.<anonymous> (http://localhost:63342/atMoon/www/lib/ionic/js/ionic.bundle.js:42066:13)
at http://localhost:63342/atMoon/www/lib/ionic/js/ionic.bundle.js:10674:10
at Array.forEach (native)
這是為什麼
引入
$state
服务,然后使用$state.go
即可。具體參數看文檔:$state#go遇到了同樣的問題!
引入了$state服務,但還是出現相同的問題,不知道你解決了沒有?
$httpProvider 攔截器
雷雷 雷雷angular.module('ngApp', ['ui.router'])
.config(函數($stateProvider, $urlRouterProvider) {
……
})
##
createAccount.html
创建了吗?createAccountCtrl
這個 JS 檔案引入到 html 中了嗎?