2016-07-07 12 views
0

こんにちは、Ionicフレームワークを使用してモバイルアプリケーションを開発しています。 私は非常に基本的な質問を知っていますが、私はこれに新しいです。 Index.htmlで は二つのボタン1を持っていることは、それまでの符号にLogin.htmlページ同様のクリックを開く]をクリックし、ログインに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および他のためのものです開く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> 

を行うか

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

$状態があなたのコントローラに注入されていることを確認してくださいのようなボタンのNG-クリックでこれを行うには、2つの方法。このリンクを使用して

+0

これをng-clickで試してみましたが、これは動作しません。 – Pritish

+0

okログインボタンがあるhtmlでは、親要素またはページでng-controller = 'LoginCtrl'を使用する必要があります。それを試すことができますか? – Srijith

+0

はい私はこれもコードを更新しました。私はng-controllerをdivタグのログインボタンに追加します – Pritish

関連する問題