登录程序无法正确导航,我认为问题出在.js代码及其位置



登录程序无法正确导航,我认为问题出在.js代码及其位置。我有一个标题,两个文本输入框,后跟两个不起作用的按钮(问题)导航看起来不错,但不幸的是它不起作用。我将在评论中发布.js,因为我不熟悉发布问题的 SO 布局。

<!DOCTYPE html> <html>   <head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>Calorific Calorie Counter</title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<link href="//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet">
<!--<script src="//code.ionicframework.com/nightly/js/ionic.bundle.js"></script>?
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
</head>   <body ng-app="calorific">
<ion-pane>
    <ion-header-bar class="bar-balanced">
      <h1 class="title">Calorific</h1>
    </ion-header-bar>
  <ion-content>
      <div class="list">
        <label class="item item-input">
          <span class="input-label">Username</span>
          <input type="text" ng-model="user.username">
        </label>
        <label class="item item-input">
          <span class="input-label">Password</span>
          <input type="password" ng-model="user.password">
        </label>
      </div>
      <div class="padding">
        <button class="button button-block button-balanced" ng-click="signIn(user)">
          Sign-In  </button>
      </div>
      <p class="text-center">
          <a href="#/forgot-password">Forgot password</a>
        </p>
  </ion-content>
</ion-pane>

<script id="templates/forgot-password.html" type="text/ng-template">
  <ion-view view-title="Forgot Password">
    <ion-content padding="true">
      <p>
        text
      </p>
      <p>
        Theres no username/password, just click
        the SignIn button back a the signin view.
      </p>
      <p>
        Return to <a href="#/sign-in">Sign-In</a>.
      </p>
    </ion-content>
  </ion-view>
  </script>

<script id="templates/tabs.html" type="text/ng-template">
  <ion-view>
    <ion-tabs class="tabs-icon-top tabs-positive">
      <ion-tab title="Home" icon="ion-home" href="#/tab/home">
        <ion-nav-view name="home-tab"></ion-nav-view>
      </ion-tab>
      <ion-tab title="About" icon="ion-ios-information" href="#/tab/about">
        <ion-nav-view name="about-tab"></ion-nav-view>
      </ion-tab>
      <ion-tab title="Sign-Out" icon="ion-log-out" href="#/sign-in">
      </ion-tab>
    </ion-tabs>
  </ion-view>
  </script>

<script id="templates/home.html" type="text/ng-template">
  <ion-view view-title="Home">
    <ion-content padding="true">
      <p>Example of Ionic tabs. </p>
      <p>
        <a class="button icon icon-right ion-chevron-right" href="#/tab/tester">tester text</a>
      </p>
    </ion-content>
  </ion-view>
  </script>

<script id="templates/tester.html" type="text/ng-template">
  <ion-view view-title="tester">
    <ion-content padding="true">
      <p>text</p>
      <p>text</p>
      <p>text</p>
      <p>text</p>
      <p>text</p>
      <p>
        <a class="button icon ion-home" href="#/tab/home"> Home</a>
        <a class="button icon icon-right ion-chevron-right" href="#/tab/tester2">testert2</a>
      </p>
    </ion-content>
  </ion-view>
  </script>
<script id="templates/tester2.html" type="text/ng-template">
  <ion-view view-title="testert2">
    <ion-content padding="true">
      <p>text</p>
      <p>text</p>
      <p>text</p>
      <p>text</p>
      <p>text</p>
      <p>text</p>
      <p>
        <a class="button icon ion-home" href="#/tab/home"> Home</a>
        <a class="button icon ion-chevron-left" href="#/tab/tester"> tester text</a>
      </p>
    </ion-content>
  </ion-view>
  </script>
<script id="templates/about.html" type="text/ng-template">
  <ion-view view-title="About">
    <ion-content padding="true">
      <h3>header</h3>
      <p>text</p>
      <p>text</p>
      <p>
        <a class="button icon icon-right ion-chevron-right" href="#/tab/navstack">Tabs Nav Stack</a>
      </p>
    </ion-content>
  </ion-view>
</script>
<script id="templates/nav-stack.html" type="text/ng-template"
  <ion-view view-title="Tab Nav Stack">
    <ion-content padding="true">
      <p><img src="http://ionicframework.com/img/diagrams/tabs-nav-stack.png" style="width:100%"></p>
    </ion-content>
  </ion-view>
</script>
</body> </html>

Javascript:

angular.module('calorific', ['ionic'])
    .run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if(window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
}) 
.config(function($stateProvider, $urlRouterProvider) {
    $stateProvider
      .state('signin', {
        url: '/sign-in',
        templateUrl: 'templates/sign-in.html',
        controller: 'SignInCtrl'
      })
      .state('forgotpassword', {
      url: '/forgot-password',
      templateUrl: 'templates/forgot-password.html'
      })
      .state('tabs', {
        url: '/tab',
        abstract: true,
        templateUrl: 'templates/tabs.html'
      })
      .state('tabs.home', {
        url: '/home',
        views: {
          'home-tab': {
            templateUrl: 'templates/home.html',
            controller: 'HomeTabCtrl'
          }
        }
      })
      .state('tabs.tester', {
        url: '/tester',
        views: {
          'home-tab': {
            templateUrl: 'templates/tester.html'
          }
        }
      })
      .state('tabs.tester2', {
        url: '/tester2',
        views: {
          'home-tab': {
            templateUrl: 'templates/tester2.html'
          }
        }
      })
      .state('tabs.about', {
        url: '/about',
        views: {
          'about-tab': {
            templateUrl: 'templates/about.html'
          }
        }
      })
      .state('tabs.navstack', {
        url: '/navstack',
        views: {
          'about-tab': {
            templateUrl: 'templates/nav-stack.html'
          }
        }
      })
      .state('tabs.contact', {
        url: '/contact',
        views: {
          'contact-tab': {
            templateUrl: 'templates/contact.html'
          }
        }
      });

     $urlRouterProvider.otherwise('/sign-in');
  })
.controller('SignInCtrl', function($scope, $state) {
   $scope.signIn = function(user) {
   console.log('Sign-In', user);
   $state.go('tabs.home');   };    })
.controller('HomeTabCtrl', function($scope) {  
  console.log('HomeTabCtrl'); });

由于您还没有提供足够的信息,我只能假设。

单击按钮时,您是否会获得日志? console.log('Sign-In', user);您是否从主页获取日志? console.log('HomeTabCtrl');

您在控制台中看到的错误是什么?

我建议您检查应用程序.run部分中的状态更改错误:

$rootScope.$on("$stateChangeError", function (event, toState, toParams, fromState, fromParams, error) {
  console.log("State change error!"); 
  console.log(error);
});

这会告诉您状态是否有问题。 模板或控制器可能不存在。

相关内容

  • 没有找到相关文章

最新更新