当我用angularJs在Ionic上闲逛时遇到问题,当我尝试开发登录页面时,问题出在路由系统中。
在代码的 Controller 部分,我尝试使用state.go(psc.dash)加载欢迎页面,称为“破折号”

这是我的 controller.js :

angular.module('starter.controllers', [])
    .controller('LoginCtrl', function($location, $state) {
        var user = this;

        user.login = function() {
            console.log("LOGIN user: " + user.email + " - PW: " + user.password);
            setTimeout(function() {
                state.go('psc.dash');
            }, 20);
        };
    })
   .controller('DashCtrl', function($scope, $location) {});

这是我的App.js:
.config(function($stateProvider, $urlRouterProvider, $locationProvider) {
  $stateProvider

  .state('login', {
    url: "/login",
    views: {
      'login': {
        templateUrl: "templates/login.html",
        controller: "LoginCtrl"
      }
    }
  })
  .state('psc', {
    url: "/psc",
    abstract: true,
    templateUrl: "templates/psc.html"
  })
  .state('psc.dash', {
    url: "/dash",
    views: {
      'psc-dash': {
        templateUrl: "templates/dash.html",
        controller: "DashCtrl"
      }
    }
  })
  ;

  // if none of the above states are matched, use this as the fallback
  $urlRouterProvider.otherwise('/login');
});

这是我的 login.html
<div class="list list col span_1_of_2 " ng-controller="LoginCtrl as loginCtrl">
    <label class="item item-input">
        <span class="input-label">E-mail</span>
        <input type="text" ng-model="loginCtrl.email">
    </label>
    <label class="item item-input">
        <span class="input-label">password</span>
        <input type="password" ng-model="loginCtrl.password">
    </label>
    <div>
        <div class="col span_2_of_3"><a href="  ">forgot password ? </a></div>
        <button class="button button-positive  col span_1_of_3" ng-click="loginCtrl.login()">
            connect
        </button>
    </div>
</div>

问题是,当我单击“连接”按钮时,地址栏中显示网址“/ psc / dash”,但登录 View 保持显示状态,并且该页面未重新加载新的html View 。

最佳答案

编辑

错了ui-router文档中存在一个差异:states that inherit from an abstract state are prefixed with their parents URL

原因是,尽管您的'psc.dash'嵌套状态被定义为'psc'状态的子级,但是分配给它的URL不会自动以其父级URL开头。

您想要将'psc.dash'状态定义更改为此:

.state('psc.dash', {
    url: "/psc/dash",
    views: {
      'psc-dash': {
        templateUrl: "templates/dash.html",
        controller: "DashCtrl"
      }
    }
  })

看看ui-router documentation的原因:

10-06 08:21