2014-12-02 43 views
4

我在Ionic中有一個表單,我試圖返回文本框的值,但是有問題。表單的其餘部分正在加載,'註冊'返回到控制檯。 formData.email沒有綁定在模板中,當我鍵入內容並單擊按鈕時,它們都不會返回到控制檯。如何使用Ionic返回文本框的值?

任何建議怎麼辦?

signup.html

<!-- Header --> 
<div class="bar bar-header bar-light"> 

    <button class="button icon-left ion-chevron-left button-clear button-dark">Back</button> 

    <h1 class="title">Signup</h1> 
</div> 

<!-- Space between header and signup form --> 
<div class="spacer" style="width: 300px; height: 50px;"></div> 


<div class="list list-inset"> 

    <!-- Signup form text fields --> 
    <form> 

     <label class="item item-input"> 
      <span class="input-label">Email</span> 
      <input type="email" ng-model="formData.email"> 
     </label> 



     <label class="item item-input"> 
     <span class="input-label">Username</span> 
     <input type="text"> 
     </label> 

     <label class="item item-input"> 
     <span class="input-label">Password</span> 
     <input type="password"> 
     </label> 

     <!-- Submit button for signup form --> 
     <button on-touch="onTouch()" class="button button-positive button-block"> 
      Sign up 
     </button> 

    </form> 
</div> 

{{formData.email}} 

controllers.js

.controller('SignupCtrl', function($scope, $ionicLoading, $state, $stateParams){ 
    console.log('signup'); 

    $scope.formData = {}; 

    //Go to the guessing page 
    $scope.onTouch = function(item,event){ 
     console.log($scope.formData.email); 
    }; 



}); 

回答

3

你在做什麼是正確的,我能做的唯一的事情來重建,這是如果你還沒有進入有效的電子郵件地址,它返回undefined。這是Angular內置的驗證功能,與Ionic無關。你可以在這裏找到更多關於這個:https://docs.angularjs.org/api/ng/input/input%5Bemail%5D

相關問題