Ионный с угловым JS. кнопка не связана с другим HTML

0

Может ли кто-нибудь помочь мне в том, как это исправить? Похоже, я не могу заставить свою кнопку ссылаться на другую страницу. Я провел некоторое исследование и попытался следовать демо, но это тупик. Я не знаю, какую часть я должен исправить.

register.html

<!DOCTYPE html>
<html ng-app="starter">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title></title>

    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">

    <!-- 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 js -->
    <script src="js/app.js"></script>
  </head>
  <body ng-app="starter">

    <ion-pane>

      <ion-view view-title="Register">
        <ion-content>
          <div class="bar bar-header bar-stable">
            <h1 class="title">Register</h1>
        </div>
        <div ng-controller="RegistrationCtrl" class="content">
          <button class="button button-positive" ng-click="goToNextState()">Go to next state (page)</button>
        </div>
      </ion-content>
    </ion-view>



    </ion-pane>
  </body>
</html>

after.html

<!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></title>

    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">

    <!-- 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 js -->
    <script src="js/app.js"></script>
  </head>
  <body ng-app="starter">

    <ion-pane>

      <ion-view view-title="After">
        <ion-content>
          <div class="bar bar-header bar-stable">
            <h1 class="title">Register</h1>
        </div>
            <div ng-controller="AfterCtrl" class="content">
              <button class="button button-positive" ng-click="goToPrevState()">Go to prev state (page)</button>
            </div>
        </ion-content>
      </ion-view>


    </ion-pane>
  </body>
</html>

app.js

 var app = angular.module('starter', ['ionic'])
app.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();
    }
  });
})

app.config(function($stateProvider, $urlRouterProvider) {
        $stateProvider
            .state('register', {
                url: '/',
                templateUrl: 'register.html',
                controller: 'RegistrationCtrl'
            })
            .state('after', {
                url: 'after',
                templateUrl: 'after.html',
                controller: 'AfterCtrl'
            });
        $urlRouterProvider.otherwise('/');
    });

app.controller("RegistrationCtrl", function($scope, $location){
      $scope.goToNextState = function() {
        $location.path("/after");
      };
    });

app.controller("RegistrationCtrl", function($scope, $location){
      $scope.goToNextState = function() {
        $location.path("/after");
      };
    });
Теги:
ionic

2 ответа

0

Недавно я столкнулся с подобной проблемой. Я обнаружил, что использование

<button class="button button-positive" ui-sref="STATENAME" >Go to prev state (page)</button> исправлена моя проблема.

0

Я не смог найти контроллер AfterCtrl в вашем приложении app.js

app.controller("RegistrationCtrl", function($scope, $location){
      $scope.goToNextState = function() {
        $location.path("/after");
      };
    });

app.controller("RegistrationCtrl", function($scope, $location){
      $scope.goToNextState = function() {
        $location.path("/after");
      };
    });

Также я бы предложил использовать $state.go("register") и $state.go("after") а также не забудьте ввести $ state

функция ($ scope, $ state)

Ещё вопросы

Сообщество Overcoder
Наверх
Меню