Help me with this controller?


#1

Can someone help me on how to fix this?
seems like i cant get my button working link to another page.
i did some research and try to follow the demo but it’s dead end. i don’t know which part i should fix it.

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's 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's 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");
      };
    });

#2

if you want to navigate between page try use $state.go

like this:

app.controller(“RegistrationCtrl”, function($scope, $state){
this.goAfter = function(){
$state.go(‘after’);
}
});

In html try use:
< div ng-controller=“AfterCtrl as ctrl” class=“content” >
< button class=“button button-positive” ng-click=“ctrl.goAfter()”>Go to prev state (page)