suchen

Heim  >  Fragen und Antworten  >  Hauptteil

angular.js - angular-ui-route中重定向页面js代码怎么写?

还是$location.path()么

我的代码是这样的:

 $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) 

这是为什么

高洛峰高洛峰2775 Tage vor717

Antworte allen(5)Ich werde antworten

  • 大家讲道理

    大家讲道理2017-05-15 16:52:02

    引入 $state 服务,然后使用 $state.go 即可。具体参数看文档:$state#go

    Antwort
    0
  • PHP中文网

    PHP中文网2017-05-15 16:52:02

    遇到了同样的问题!

    .controller('CinemasCtrl', function($scope, $rootScope, $state) {
            ...
    
            $scope.show = function(cinemaId) {
              $state.go('cinema.info', { id: cinemaId });
            };
    
            ...
    })
    

    引入了$state服务,但是还是出现相同的问题,不知道你解决了没有?

    Antwort
    0
  • 高洛峰

    高洛峰2017-05-15 16:52:02

    $httpProvider interceptor

    .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);
            }
          };
              }])
    

    Antwort
    0
  • 仅有的幸福

    仅有的幸福2017-05-15 16:52:02

    angular.module('ngApp', ['ui.router'])
    .config(function ($stateProvider, $urlRouterProvider) {
    ……
    })
    ##

    Antwort
    0
  • PHP中文网

    PHP中文网2017-05-15 16:52:02

    state('createAccout', {
      url:'/createAccount',
        templateUrl:'js/pages/createAccount.html',
        controller:'createAccountCtrl'
      })
    

    createAccount.html 创建了吗?
    createAccountCtrl 这个 JS 文件引入到 html 中了吗?

    Antwort
    0
  • StornierenAntwort