maverick
maverick

Reputation: 37

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. 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.

 <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 :

$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:

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. Firebug Picture

HTML view

Upvotes: 1

Views: 530

Answers (2)

Kayvan Salimi
Kayvan Salimi

Reputation: 335

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. Remove pattern="[0-9]" and try again.

Upvotes: 1

Julio Bastida
Julio Bastida

Reputation: 1219

If you are using ng-model there is no need for you tu pass it's value as a function parameter. You can access the current value directly on the controller via

$scope.Nbid;

Reference: NgModel Documentation

Upvotes: 0

Related Questions