2016-07-12 92 views
1

不開放有它SignUp Button而點擊它它不是打開signup.html頁面註冊頁面離子

的login.html的index.html的

<body ng-app="starter" ng-controller="AppCtrl"> 
    <ion-nav-bar class="bar-calm"> 
    </ion-nav-bar> 
    <ion-nav-view></ion-nav-view> 
</body> 

的login.html

<ion-view view-title="Sign-In" name="login-view"> 
    <ion-content class="padding"> 
    <button class="button button-block button-positive" ng-click="signup()">SignUp</button> 
    </ion-content> 
</ion-view> 

app.js

angular.module('starter', ['ionic', 'ngMockE2E','ui.router']) 
    .run(function ($ionicPlatform) { 
     $ionicPlatform.ready(function() { 
      if (cordova.platformId === 'ios' && window.cordova && window.cordova.plugins.Keyboard) { 
       cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
       cordova.plugins.Keyboard.disableScroll(true); 
      } 
      if (window.StatusBar) { 
       StatusBar.styleDefault(); 
      } 
     }); 
    }) 

    .config(function ($stateProvider, $urlRouterProvider, USER_ROLES) { 
     $stateProvider 

    .state('login', { 
     url: '/login', 
     templateUrl: 'templates/login.html', 
     controller: 'LoginCtrl' 
    }) 
     .state('signup', { 
      url: '/signup', 
      templateUrl: 'templates/signup.html', 
      controller: 'SignupCtrl' 
     }) 
     $urlRouterProvider.otherwise('/login'); 
    }) 

controller.js

.controller('AppCtrl', function ($scope, $state, $ionicPopup, AuthService, AUTH_EVENTS) { 
    $scope.username = AuthService.username(); 

    $scope.$on(AUTH_EVENTS.notAuthorized, function (event) { 
     var alertPopup = $ionicPopup.alert({ 
      title: 'Unauthorized!', 
      template: 'You are not allowed to access this resource.' 
     }); 
    }); 

    $scope.$on(AUTH_EVENTS.notAuthenticated, function (event) { 
     AuthService.logout(); 
     $state.go('login'); 
     var alertPopup = $ionicPopup.alert({ 
      title: 'Session Lost!', 
      template: 'Sorry, You have to login again.' 
     }); 
    }); 

    $scope.setCurrentUsername = function (name) { 
     $scope.username = name; 
    }; 
}) 

     .controller("SignupCtrl", function ($scope, $state, $ionicPopup, AuthService) { 
       $scope.data = {}; 
       $scope.signup = function() { 
        $state.go('singup'); 
       }; 
      }) 

    .controller('LoginCtrl', function ($scope, $state, $ionicPopup, AuthService) { 
     $scope.data = {}; 

     $scope.login = function (data) { 
      AuthService.login(data.username, data.password).then(function (authenticated) { 
       $state.go('main.dash', {}, { reload: true }); 
       $scope.setCurrentUsername(data.username); 
      } 
     }; 
    }) 

templates folder內部有signup.html

<ion-view view-title="Signup" name="Signup-view"> 
    <ion-content padding="true" class="has-header"> 
     <form id="signup-form2" class="list "> 

    // sign up fields goes here..... 

    <a ui-sref="login" id="signup-button5" style="border-radius:15px 15px 15px 15px;" class="button button-calm button-block" ng-click="signupEmail(data)">Sign up</a> 
     </form> 
    </ion-content> 
</ion-view> 
+1

你的登錄狀態聲明和控制器在哪裏?或者你剛剛離開這個例子嗎? – thepio

+0

謝謝!所以在控制檯中沒有錯誤日誌,所以從來沒有? – thepio

+0

沒有這樣的控制檯錯誤日誌。現在 – Pritish

回答

1

我認爲你缺少的狀態變化功能在你的LoginCtrl。所以你應該在LoginCtrl中聲明它,因爲該控制器在login.html中使用。

.controller("LoginCtrl", function ($scope, $state) { 
    $scope.signup = function() { 
    $state.go('signup'); 
    }; 
}) 

同時認爲,在你的示例代碼,你曾在$state.go功能的錯字。你的州名是singup,應該是signup

+0

我沒有聲明LoginCtrl中的SignupCtrl都是不同的範圍。 – Pritish

+0

不,但你需要在你的'LoginCtrl'中聲明'ng-click =「註冊()」''。假設你在login.html中有'',那麼你需要在'LoginCtrl'中聲明'awesomeFunction',像這樣'$ scope.awesomeFunction = function (){alert('這很棒'); }'。希望我清楚我想說什麼。 – thepio

+0

感謝您的回覆,我根據您的建議完成了更改。它提示提醒但不打開頁面。 – Pritish