javascript - ionic 改变位置不起作用

标签 javascript angularjs ionic-framework

我是 ionic 的新手(在 angularjs 方面略逊一筹)。

我正在尝试在两个 View 之间进行简单的切换:

HTML

<body ng-app="starter" animation="slide-left-right-ios7">
    <!-- 
      The nav bar that will be updated as we navigate between views.
    -->
    <ion-nav-bar class="bar-stable nav-title-slide-ios7">
      <ion-nav-back-button class="button-icon icon  ion-ios7-arrow-back">
        Back
      </ion-nav-back-button>
    </ion-nav-bar>

    <ion-nav-view name="intro"></ion-nav-view>
    <ion-nav-view name="login"></ion-nav-view>
    <ion-nav-view name="home"></ion-nav-view>
    <ion-nav-view name="pizze"></ion-nav-view>
    <ion-nav-view name="sponsor"></ion-nav-view>
    <ion-nav-view name="scontrino"></ion-nav-view>
  </body>

APP.js

.config(function($stateProvider, $urlRouterProvider) {

  // Ionic uses AngularUI Router which uses the concept of states
  // Learn more here: https://github.com/angular-ui/ui-router
  // Set up the various states which the app can be in.
  // Each state's controller can be found in controllers.js
  $stateProvider


    .state('intro', {
      url: '/intro',
      views: {
        'intro': {
          templateUrl: 'templates/intro.html',
          controller: 'IntroCtrl'
        }
      }
    })
    .state('login', {
      url: '/login',
      views: {
        'login': {
          templateUrl: 'templates/login.html',
          controller: 'LoginCtrl'
        }
      }
    })
  $urlRouterProvider.otherwise('/intro');

});

Controllers.js

angular.module('starter.controllers', [])

.controller('IntroCtrl', function($scope,$location) {
    $location.url("/login");

})
.controller('LoginCtrl', function($scope,$location) {

})

Intro 显示正确,但当它尝试将位置更改为“login.html”时,它说:

TypeError: Cannot read property 'querySelectorAll' of undefined
    at cancelChildAnimations (http://localhost:8000/www/lib/ionic/js/ionic.bundle.js:30611:21)
    at Object.leave (http://localhost:8000/www/lib/ionic/js/ionic.bundle.js:30176:11)
    at Object.leave (http://localhost:8000/www/lib/ionic/js/ionic.bundle.js:38411:24)
    at updateView (http://localhost:8000/www/lib/ionic/js/ionic.bundle.js:41540:31)
    at eventHook (http://localhost:8000/www/lib/ionic/js/ionic.bundle.js:41501:17)
    at Scope.$broadcast (http://localhost:8000/www/lib/ionic/js/ionic.bundle.js:21190:28)
    at $state.transition.resolved.then.$state.transition (http://localhost:8000/www/lib/ionic/js/ionic.bundle.js:33975:22)
    at wrappedCallback (http://localhost:8000/www/lib/ionic/js/ionic.bundle.js:19894:81)
    at http://localhost:8000/www/lib/ionic/js/ionic.bundle.js:19980:26
    at Scope.$eval (http://localhost:8000/www/lib/ionic/js/ionic.bundle.js:20906:28) 

可能是什么问题???

谢谢!

最佳答案

试试这个

angular.module('starter.controllers', [])

.controller('IntroCtrl', function($scope,$state) {
     $state.transitionTo("login");

})
.controller('LoginCtrl', function($scope,$location) {

})

关于javascript - ionic 改变位置不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23928982/

相关文章:

javascript - AngularJS 中的条件

javascript - 根据首字母过滤ng-repeat

html - Ionic 2/angular 2 - 如何将带有 Typescript 的 HTML 元素添加到我的组件中?

c# - 从 request.querystring 中删除字符

JavaScript Canvas 游戏在一段时间后下降 FPS

Javascript 登场——从 Chrome 控制台到小书签

javascript - 如何在原生 javascript 中实现 $ ("<div class=' wrapper'><span>Some text</span></div>")?

angularjs - 如何使用 Angular Scenario Runner 运行测试套件的子集?

ionic-framework - Ionic 2 将按钮标签向左对齐

php - 将 AngularJs 连接到本地服务器 php MySQL