簡體   English   中英

無法使用Angular.js從輸入字段獲取值

[英]Can not get the value from input field using Angular.js

嘗試使用Angular.js從輸入字段獲取值時遇到問題。 我在下面解釋我的代碼。

在我的控制器代碼如下。

$scope.shipping=0;
$scope.addProductInfoData=function(billdata){
        console.log('valid',$scope.shipping);
}

我的看法部分如下。

<div class="input-group bmargindiv1 col-md-12">
<span class="input-group-addon ndrftextwidth text-right" style="width:180px">Shipping charge :</span>
<div ng-class="{ 'myError': billdata.ship.$touched && billdata.ship.$invalid }">
<input type="text" name="ship" id="shippingcharge" class="form-control" placeholder="Add shipping charge" ng-model="shipping" ng-keypress="clearField('shippingcharge');" ng-pattern="/^[0-9]+([,.][0-9]+)?$/">
<div style="clear:both;"></div>
</div>
</div>
<div class="help-block" ng-messages="billdata.ship.$error" ng-if="billdata.ship.$touched || billdata.usp.$error.pattern">
<p ng-message="pattern" style="color:#F00;">This field needs only number(e.g-0,1..9).</p>
</div>
<input type="button" class="btn btn-success" ng-click="addProductInfoData(billdata);"  id="addProfileData" value="Add"/>

在這里,當我單擊控制台消息內的添加按鈕時,我應該得到的出廠值為0。但是在這里,我得到的是undefined.Value,請幫助我解決此問題。

您尚未定義shipping_status 這就是為什么它等於undefined 可能是您的變量名中有錯字或打算使用$scope.shipping

改變這個

console.log('valid',$scope.shipping_status);

console.log('valid',$scope.shipping);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM