简体   繁体   English

从 HTML 获取 Angular 的未定义值

[英]Getting an undefined value at Angular from HTML

I am passing the values from HTML to Angular using ng-modal but its giving me undefined at Angular.我正在使用 ng-modal 将值从 HTML 传递到 Angular,但它在 Angular 中给了我未定义的值。 I am passing the value through ng-click to pass value to the Angular, where I am making use of the firebug options to check my values at Angular.我正在通过 ng-click 传递值以将值传递给 Angular,在那里我使用 firebug 选项来检查我在 Angular 的值。

 <div class ="row"> 
<div class="col-md-3 col-md-offset-1">
<p>Bid Price<input type= "text" class="form-control" name="Nbid" id="Nbid" ng-model ="Nbid"  pattern="[0-9]" style="width:90px" ></p>

<div class="col-md-5 col-md-offset-1"> <br> 
<p><button type="button" class="btn btn-primary" ng-click="placeBid(result.ITEM_CODE ,Nbid, result.ITEM_NAME, result.ITEM_DESC);" style="width:120px"> Place Bid</button></p></div</div> 

On Angular side the code is :在 Angular 方面,代码是:

$scope.placeBid = function(ITEMCODE, Nbid, ITEM_NAME, ITEM_DESC){
$scope.value = ITEMCODE;
$scope.bidpr = Nbid;
$scope.ITEM_NAME = ITEM_NAME;
$scope.ITEM_DESC = ITEM_DESC;

console.log($scope.value);
console.log($scope.bidpr);
console.log($scope.ITEM_NAME);
console.log($scope.ITEM_DESC);

On Firebug console I am getting this values printed:在 Firebug 控制台上,我打印了以下值:

console.log($scope.value);     --->  15
console.log($scope.bidpr);     ---->  undefined
console.log($scope.ITEM_NAME);  ----> J.K TWINGING
console.log($scope.ITEM_DESC); ---- > SAHIL MON  MYSTERY 

I am not sure where I am making mistake in the code that I can see the value of the bid as undefined.我不确定我在代码中哪里出错了,我可以看到出价的价值未定义。 萤火虫图片

HTML 视图

You are using pattern="[0-9]" attribute in your input , according to these only you can put just one digit in it, so I think you are put more than one digit in it therefor the ng-model lost its data.您在input中使用pattern="[0-9]"属性,根据这些,您只能在其中input一位数字,所以我认为您在其中输入了不止一位数字,因为ng-model丢失了数据. Remove pattern="[0-9]" and try again.删除pattern="[0-9]"试。

If you are using ng-model there is no need for you tu pass it's value as a function parameter.如果您使用的是 ng-model,则无需将其值作为函数参数传递。 You can access the current value directly on the controller via您可以通过以下方式直接在控制器上访问当前值

$scope.Nbid;

Reference: NgModel Documentation参考: NgModel 文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM