2016-07-07 139 views
0

嗨使用Ionic Framework開發移動應用程序。 我知道它的基本問題,但我對此很陌生。 在Index.html是一種有兩個按鈕,1是Login等爲SignUp無法在按鈕上點擊打開新頁面

enter image description here

的index.html

<script src="js/app.js"></script> 
     <script src="js/controllers.js"></script> 
     <script src="js/directives.js"></script> 
     <script src="js/services.js"></script> 
     <script src="js/routes.js"></script> 
    </head> 
    <body ng-app="starter" ng-controller="MainCtrl"> 
      <ion-pane> 
      <div class="bar bar-header bar-calm"> 
      <h1 class="title">Heading</h1> 
     </div> 

       <ion-content paging="true" class="has-header" > 
        <div> 
         <img src="img/Logo.jpg" width="100%" height="auto" style="display:block;margin-left:auto;margin-right:auto;" /> 
         <img src="img/Team.jpg" width="70%" height="auto" style="display:block;margin-left:auto;margin-right:auto;" /> 
        </div> 
        <div ng-cntroller="loginCtrl"> 
         <button id="btnLogin" class="icon icon-right ion-log-in left button button-positive button-block " style="border-radius:15px 15px 15px 15px;" ng-click="login()">Login</button> 
</div> 
<div ng-cntroller="signupCtrl"> 
         <button id="btnSignUp" class="button button-positive button-block icon icon-right ion-person left" style="border-radius:15px 15px 15px 15px;">SignUp</button> 
        </div> 
        <div class="bar bar-footer bar-calm"> 
         <div class="title">Copyright <strong>@</strong></label> 
        </div> 

       </ion-content> 

      </ion-pane> 

在登錄點擊打開標誌Login.html頁面類似的方式點擊了它打開Signup.html

app.js

angular.module('starter', ['ionic','starter.controllers','starter.routes','starter.services','starter.directives']) 

.run(function($ionicPlatform) { 
    $ionicPlatform.ready(function() { 
    if(cordova.platformId === 'ios' && window.cordova && window.cordova.plugins.Keyboard) { 
     // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard 
     // for form inputs) 
     cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 

     // Don't remove this line unless you know what you are doing. It stops the viewport 
     // from snapping when text inputs are focused. Ionic handles this internally for 
     // a much nicer keyboard experience. 
     cordova.plugins.Keyboard.disableScroll(true); 
    } 
    if(window.StatusBar) { 
     StatusBar.styleDefault(); 
    } 
    }); 
}) 

routes.js

var app = angular.module('starter', []) 

app.config(function($stateProvider,$urlRouteProvider){ 
    $stateProvider 

    .state('text', { 
     url: '/page1', 
     templateUrl: 'templates/text.html', 
     controller: 'textCtrl' 
    }); 

    .state('login', { 
     url: '/page2', 
     templateUrl: 'templates/login.html', 
     controller: 'loginCtrl' 
    }); 

    .state('signUp', { 
     url: '/page3', 
     templateUrl: 'templates/signup.html', 
     controller: 'signupCtrl' 
    }); 

    .state('chats', { 
     url: '/page4', 
     templateUrl: 'templates/chats.html', 
     controller: 'chatsCtrl' 
    }); 

    $urlRouteProvider.otherwise('/page1') 
}); 

controllers.js

var app = angular.module('starter') 
app.controller('textCtrl',function($scope){ 

}); 


app.controller('loginCtrl', function ($scope) { 
$scope.login = function(){ 
alert("Hi")}; 

}); 

app.controller('signUpCtrl', function ($scope) { 

}); 

app.controller('chatsCtrl', function ($scope) { 

}); 

的login.html

<ion-view title="Login" id="page2" class=" "> 
    <ion-content padding="true" class="has-header"> 
     <form id="login-form1" class="list "> 
      <ion-list id="login-list1" class=" "> 
       <label class="item item-input " id="login-input1"> 
        <span class="input-label">Username</span> 
        <input type="text" placeholder=""> 
       </label> 
       <label class="item item-input " id="login-input2"> 
        <span class="input-label">Password</span> 
        <input type="password" placeholder=""> 
       </label> 
      </ion-list> 
      <div class="spacer" style="height: 40px;"></div> 
      <a ui-sref="chats" id="login-button3" style="border-radius:15px 15px 15px 15px;" class=" button button-calm button-block ">Log in</a> 
      <a ui-sref="signup" id="login-button4" class=" button button-positive button-block button-clear ">Or create an account</a> 
     </form> 
    </ion-content> 
</ion-view> 
+0

創建撥弄,而不是粘貼所有的代碼。 –

回答

0

您需要定義登錄按鈕應該做的事情。兩種方法去

要麼

<button id="btnLogin" ui-sref="login">Login</button> 

或做這個按鈕的NG-點擊喜歡

$scope.login = function(){ 
$state.go('login'); 
}; 

確保$狀態被注入到控制器。

+0

我嘗試了用NG點擊這一點,但沒有工作 – Pritish

+0

確定我只注意到在你的HTML,你必須登錄按鈕,你需要的父元素或頁面上使用NG-控制器=「LoginCtrl」。你可以試試嗎? – Srijith

+0

是的,我試過這也是我更新了代碼。我添加ng控制器登錄按鈕在div標記 – Pritish