输入字段模型值在控制器中未定义

时间:2015-10-05 07:42:05

标签: angularjs ionic

 <ion-view cache-view="false">
  <ion-content class="has-header has-smallsubheader" >
  <form name="$root.deliveryDetails" action="#">
  <div>
  <div class="paddingOnSides">
   <p><input type="number" name="usermobileNumber" ng-model="userEnteredMobileNumber" />                                                 </p> 
 <div>
 <span class="button" ng-click="checkRegisteredUsers()">Verify</span>
 </div>
  </div>
  </ion-view>
 </ion-content>

控制器:

$scope.checkRegisteredUsers = function(){
  console.log($scope.userEnteredMobileNumber)  //gives undefined
}

我尝试在ng-model字段formData.userEnteredMobileNumber中使用对象而不是原语,但我仍然未定义。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

使用相同的代码创建了一个样本plunkr并且工作正常。

    <body ng-controller="MainCtrl">
   <form name="$root.deliveryDetails" action="#">
      <div>
         <div class="paddingOnSides">
            <p><input type="number" name="usermobileNumber" ng-model="userEnteredMobileNumber" /></p>
            <div>
               <span class="button" ng-click="checkRegisteredUsers()">Verify</span>
            </div>
         </div>
         <p>Mobile {{userEnteredMobileNumber}}!</p>
      </div>
   </form>
</body>

http://plnkr.co/edit/LNxCpKy7yn3HttI2Tc3B?p=preview