Kod saya adalah seperti ini:
$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'
})
Konsol penyemak imbas melaporkan ralat berikut:
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)
Kenapa ini
擁有18年軟件開發(fā)和IT教學(xué)經(jīng)驗(yàn)。曾任多家上市公司技術(shù)總監(jiān)、架構(gòu)師、項(xiàng)目經(jīng)理、高級(jí)軟件工程師等職務(wù)。 網(wǎng)絡(luò)人氣名人講師,...
Perkenalkan perkhidmatan $state
, dan kemudian gunakan $state.go
. Lihat dokumentasi untuk parameter tertentu: $state#go
Menghadapi masalah yang sama!
.controller('CinemasCtrl', function($scope, $rootScope, $state) {
...
$scope.show = function(cinemaId) {
$state.go('cinema.info', { id: cinemaId });
};
...
})
Perkhidmatan $state telah diperkenalkan, tetapi masalah yang sama masih berlaku Adakah anda telah menyelesaikannya?
$httpProvider pemintas
.factory('auth403', ['$rootScope', '$q', '$location', function auth403($rootScope, $q, $location) {
return {
request: function (config) {
console.log(config);
var start = new Date();
return config;
},
response: function (result) {
return result;
},
responseError: function (rejection) {
console.warn('Failed with http', (rejection.message || rejection.status), 'status');
if (rejection.status == 403) {
console.warn('Forbidden, need login to auth');
$location.path('/login');
}
return $q.reject(rejection);
}
};
}])
angular.module('ngApp', ['ui.router'])
.config(fungsi ($stateProvider, $urlRouterProvider) {
……
})
##
state('createAccout', {
url:'/createAccount',
templateUrl:'js/pages/createAccount.html',
controller:'createAccountCtrl'
})
createAccount.html
Dibuat? createAccountCtrl
Adakah fail JS ini diimport ke dalam html?