2016-07-04 13 views
0

私は入力フィールドからユーザー名を取得しようとして、ユーザーアカウントを作成するために関数に渡していますが、フィールドに入力されたユーザー名はモデルで更新されているようです。 enter image description hereAngularjsモデルがビュー入力フィールドから更新されていませんか?

私はwindow.alertを使って、テスト目的のためだけにユーザー名を表示しました。

login.htmlと

ion-view view-title="Login"> 
    <ion-content> 

     <div class="list list-inset" padding> 

      <div class="item-divider" align="center"> Login</div> 

      <label class="item item-input"> 
       <span class="input-label">UserName</span> 
       <input ng-model="username" type="text" placeholder="Email"> 
      </label> 

      <label class="item item-input"> 
       <span class="input-label">Password</span> 
       <input ng-model="password" type="password" placeholder="Your Password"> 
      </label> 

     </div> 
     <center><button class="button button-positive " ng-click="log()">Login</button> </center> 

app.js(全体ではなくコード)

blog.config(function($stateProvider,$urlRouterProvider){ 
    $stateProvider 
     .state('mainlist',{ 
     url:'/mainlist', 
     templateUrl:'templates/MainList.html', 
     controller:'listCtrl' 
    }) 
     .state('login',{ 
     url:'/login', 
     templateUrl:'templates/login.html', 
     controller:'loginCtrl' 
     }); 
blog.controller('loginCtrl',function($scope) 
       { 
         $scope.log=function() 
         { 
          var username= $scope.username; 
          window.alert(username); 
         } 

        } 
       ); 
+1

http://stackoverflow.comこの回答を参照してください。/questions/36177702/ionic-framework-scope-is-un-in-simple-alert –

+1

ありがとうPankaj Parkarそれは働いた! – mhrzn

答えて

0

あなたはモデルを定義するために最初にする必要があります。 (テストしていません)あなたのコードは、これに変更し、それが動作するはずです:

blog.config(function($stateProvider,$urlRouterProvider){ 
    $stateProvider 
     .state('mainlist',{ 
     url:'/mainlist', 
     templateUrl:'templates/MainList.html', 
     controller:'listCtrl' 
    }) 
     .state('login',{ 
     url:'/login', 
     templateUrl:'templates/login.html', 
     controller:'loginCtrl' 
     }); 


blog.controller('loginCtrl',function($scope) 
       { 

         $scope.username = ""; 
         $scope.log=function() 
         { 
          var username= $scope.username; 
          window.alert(username); 
         } 

        } 
       ); 
0
<label class="item item-input"> 
       <span class="input-label">UserName</span> 
       <input ng-model="data.username" type="text" placeholder="Email"> 
</label> 

app.js

blog.controller('loginCtrl',function($scope) 
      { 
        $scope.data={}; 
        $scope.log=function() 
        { 
         var username= $scope.data.username; 
         window.alert(username); 
        } 

       } 
      ); 

enter image description here

+0

コントローラーを定義しているときに 'controllerAs'パターンを使うのが好ましい –

+1

Angularjsを学んでいるだけです、sugedstionのおかげで – mhrzn

関連する問題