$ state.go引导我进入否则声明并且没有转换到正确的状态

时间:2016-12-19 17:54:42

标签: javascript angularjs ionic-framework

我正在尝试进入menu.home状态,但是当我执行self.button14.connect("clicked", self.button14_click, "division") def button14_click(self, button, data): self.entry.set_text(self.entry.get_text() + str("/")) self.equal_clicked() self.arithmetic = data 时它没有做任何事情,而是进入了其他语句。不确定我做错了什么。

Controller.js

$state.go('menu.home)

routes.js

$state.go('menu.home');

每当我尝试angular.module('app.routes', []) .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('login', { cache: false, url:'/login', templateUrl: 'templates/login.html', controller: 'LoginCtrl' }) .state('menu.home', { cache: false, url: '/home', views: { 'side-menu21': { templateUrl: 'templates/home.html', controller: 'MapCtrl' //'homeCtrl' } } }) .state('menu.cart', { url: '/page2', views: { 'side-menu21': { templateUrl: 'templates/cart.html', controller: 'cartCtrl' } } }) .state('menu.cloud', { url: '/page3', views: { 'side-menu21': { templateUrl: 'templates/cloud.html', controller: 'cloudCtrl' } } }) .state('menu.test', { cache: false, url: '/test', views: { 'side-menu21': { templateUrl: 'templates/test.html', controller: 'testCtrl' } } }) .state('menu', { url: '/side-menu21', templateUrl: 'templates/menu.html', abstract: true }) //$urlRouterProvider.otherwise('/login') $urlRouterProvider.otherwise(function($injector, $location) { console.log("Could not find: " + JSON.stringify($location)); $location.path('/login'); }) }); 时,这就是我得到的输出:

$state.go('menu.home')

的login.html

 Could not find:     {"$$protocol":"http","$$host":"localhost","$$port":8100,"$$path":"/app/sear    ch","$$search":    {},"$$hash":"","$$url":"/app/search","$$absUrl":"http://localhost:8100/#/ap   p/search","$$state":null,"$$replace":false}

home.html的

     <ion-view view-title="Login" id="login" name="login-view">
       <ion-content class="padding">

    <!--##########################Facebook Login#################################-->
    <div class="facebookLogin">
    <a class="facebook-sign-in button button-royal" ng-click="facebookSignIn()">Login with Facebook</a>
    </div>
    <!--#######################END Facebook Login#################################-->

          <div class="list list-inset">

              <label class="item item-input">
                  <input type="text" placeholder="Username" ng-model="data.username">
              </label>

              <

    label class="item item-input">
                  <input type="password" placeholder="Password" ng-model="data.password">
              </label>

          </div>
      <button class="button button-block button-calm" ng-click="login()">Login</button>


  </ion-content>
</ion-view>

如果我发表评论: <ion-view title="Test" id="home" class=" "> <ion-content padding="true" class="has-header"></ion-content> <body ng-app="app" ng-controller="MapCtrl"> <!-- Google Maps --> <link href="css/style.css" rel="stylesheet"> <ion-content scroll="false"> <div id="map-canvas"></div> <!-- END GOOGLE MAPS!--> <!-- Test button <div class="TestButton"> <div class="button button-assertive" ng-click="Test()" ng-hide="hideTestButton"> <a class="button">Test</a> </div> </div> End Request Test button-----------> <!-- OS/Production selection footer--> <ion-tabs class="tabs-icon-top"> <ion-tab title="Apple" icon-off="ion-social-apple" icon-on="ion-social-apple" href="#/app/search" on-select="appleTab()"> <ion-nav-view name="tab-search"></ion-nav-view> </ion-tab> <ion-tab title="Windows" icon-off="ion-social-windows" icon-on="ion-social-windows" href="#/app/browse" on-select="windowsTab()"> <ion-nav-view name="tab-browse"></ion-nav-view> </ion-tab> <ion-tab title="Mobile" icon-off="ion-iphone" icon-on="ion-iphone" href="#/app/playlists" on-select="mobileTab()"> <ion-nav-view name="tab-playlists"></ion-nav-view> </ion-tab> <ion-tab title="Network" icon-off="ion-wifi" icon-on="ion-wifi"" href="#/app/playlists" on-select="otherTab()"> <ion-nav-view name="tab-playlists"></ion-nav-view> </ion-tab> </ion-tabs> </ion-content> </body> </ion-view> 则可行。不知道为什么会这样,请帮忙!

2 个答案:

答案 0 :(得分:0)

这就是你的controller.js文件中的所有内容吗?也许那里有一些东西阻止了这种状态。请确保在主html文件中<main ui-view></main>建立所有路线。

答案 1 :(得分:0)

知道了,所以它不喜欢我在home.html的离子标签中的href。它可能正在尝试解决它们并不指向有效的URL。一旦我删除了href,它工作得非常好。感谢所有人的帮助!