2016-09-26 27 views
1

我有一个输入框按钮的输入值获取有关点击页面

<div class="inputs"> 
     <label>Online Payment ID</label> 
     <input type="text" class="form-control" ng-model="payId"> 
</div> 

我有一个按钮,页面有些地方说

<button type="button" class="btn" ng-click="proceedPayment()" ></button> 
现在

上点击proceedPayment()将被称为,从那里我需要检查上面的文本fild输入的值使用

我试过,

$scope.proceedPayment = function() { 
     alert($scope.payId); // Always alerts undefined 
    if (!$scope.payId) { 
       $scope.payIdError = true; 
       console.log('No value entered'); 
      } else { 
       $scope.payIdError = false; 
       console.log('value entered'); 
      } 
} 

但这不起作用 我不想在这里使用窗体。我是一个有角度的初学者,感谢您的帮助!

+0

@Satpal错字错误! – monda

+0

在函数中访问之前初始化'$ scope.payId'。像这样:'$ scope.payId = 10' –

+0

你可以使用一个表单,然后使用角度验证:https://docs.angularjs.org/guide/forms –

回答

3

您可以直接使用将包含用户的$scope.payId输入的值

DEMO

3

您可以使用对象

$scope.pay = {payId:null}; 


if($scope.pay.payId == null) { 
    console.log("Value not entered"); 
} else { 
     console.log("Value entered"); 
    }