angular.js - How to write the js code for the redirect page in angular-ui-route?
高洛峰
高洛峰 2017-05-15 16:50:02
0
5
711

Or $location.path()

My code is like this:

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

The browser console reports the following error:

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) 

Why is this

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(5)
大家讲道理

Just introduce $state 服务,然后使用 $state.go. See the documentation for specific parameters: $state#go

Ty80

Encountered the same problem!

.controller('CinemasCtrl', function($scope, $rootScope, $state) {
        ...

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

        ...
})

The $state service was introduced, but the same problem still occurs. Have you solved it?

小葫芦

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

仅有的幸福

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

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

createAccount.html 创建了吗?
createAccountCtrl Is this JS file introduced into html?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template