Ionic v1 $ state.go无效

时间:2017-04-27 11:09:19

标签: angularjs cordova ionic-framework

这是我的第一篇文章,我希望我足够清楚,我无法获得$ state.go工作,我一直在寻找,但我似乎没有找到答案,不太确定我做错了什么,因为我对这项技术不熟悉,我认为这实际上非常好。也许我必须在app.js中声明index.html,但我不希望一旦应用程序启动就可以访问此页面,仅在开始时,一旦用户登录,此屏幕将不再被看见,除非他们重启应用程序。

  1. 这是我的app.js

    angular.module('starter', ['ionic','starter.controllers', 'starter.services'])
    
    .config(function($ionicConfigProvider, $stateProvider, $urlRouterProvider) {
    
    $stateProvider
    
    .state('tab', {
     url: '/tab',
     abstract: true,
     templateUrl: 'templates/tabs.html'
    })
    
    .state('tab.appointments', {
     url: '/appointments',
     views: {
      'tab-appointments': {
        templateUrl: 'templates/tab-appointments.html',
        controller: 'appointmentsCtrl'
      }
     }
    })
    
    .state('tab.findPatient', {
     url: '/findPatient',
     views: {
      'tab-findPatient': {
       templateUrl: 'templates/tab-findPatient.html',
       controller: 'FindPatientCtrl'
      }
     }
    }) 
    
    .state('tab.findSlot', {
     url: '/findSlot',
     views: {
      'tab-findPatient': {
       templateUrl: 'templates/tab-findSlot.html',
       controller: 'FindPatientCtrl'
       }
      }
    })
    
    .state('tab.settings', {
     url: '/settings',
     views: {
      'tab-settings': {
       templateUrl: 'templates/tab-settings.html',
       controller: 'settingsCtrl'
       }
     }
    });
    
    $urlRouterProvider.otherwise('/tab/appointments');
    });
    
  2. 这是我的index.html

     <body ng-app="starter">
     <ion-header-bar class="bar-calm" align-title="center"></ion-header-bar>
     <ion-pane>
      <ion-content scroll="false">
       <form ng-controller="loginCtrl" name="loginCredentialsForm">
        <div class="list list-inset">
         <label class="item item-input">
          <input class="text-center" type="text" placeholder="Username" ng-model="username" required="true">
         </label>
         <label class="item item-input">
          <input class="text-center" type="password" placeholder="Password" ng-model="password" required="true">
         </label>
         <label class="item item-input">
          <input class="text-center" type="password" maxlength=4 placeholder="PIN" ng-model="practicePin" required="true">
         </label>
        </div>
        <div class="text-center">
          <button class="button button-block button-calm small_button" ng-disabled="loginCredentialsForm.$invalid" ng-click="login()" type="submit">Login</button>
        </div>
       </form>
      </ion-content>
     </ion-pane>
     </body>
    
  3. 这是我的controllers.js

    angular.module('starter.controllers', [])
    
     .controller('loginCtrl', function($scope, $state) {
    
       $scope.login = function() {
       $state.go('tab.appointments');
      };
    })
    
  4. 在此先感谢,我为任何语法错误道歉。

    已编辑 - 已添加<​​/ p>

    1. 这就是tabs.html的样子

      <ion-tabs class="tabs-icon-bottom tabs-calm">
        <ion-tab title="Appointments" icon-off="ion-ios-pulse" icon-on="ion-ios-pulse-strong" href="#/tab/appointments">
        <ion-nav-view name="tab-appointments">
        </ion-nav-view>
        </ion-tab>
      </ion-tabs>
      
    2. 然后是home.html,我很确定是重定向到tabs.html然后由其他人加载的。

         <body ng-app="starter">
          <ion-nav-bar class="bar-calm" align-title="center">
            <ion-nav-back-button>
            </ion-nav-back-button>
          </ion-nav-bar>
          <ion-nav-view></ion-nav-view>
         </body>
      
    3. 如果我将home.html的名称更改为index.html并且不使用我希望人们登录的实际index.html一切正常,但我真的需要人们登录以便他们拥有他们的自己的记录。

      This is what home.html actually looks like 正如我所说,我是这种技术的新手,试图尽我所能来理解它是如何工作的。非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

您也可以使用$window重定向到某个页面。

 $window.location.href = 'templates/tab-appointments.html'; 

您的控制器可以像这样更改

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

 .controller('loginCtrl', function($scope, $state,$window) {

   $scope.login = function() {
    $window.location.href = 'templates/tab-appointments.html'; 
  };
})
相关问题