0

I have an issue while trying to get value from input field using Angular.js. I am explaining my code below.

In my controller code is given below.

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

My view part is given below.

<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"/>

Here when i am clicking on add button inside console message i should get the shipping value is 0.But here i am getting value as undefined.Please help me to resolve this issue.

5
  • There is no model as shipping_status Commented Jan 27, 2016 at 5:19
  • where is shipping_status. Also should always use object in ng-model stackoverflow.com/questions/17606936/angularjs-dot-in-ng-model Commented Jan 27, 2016 at 5:20
  • 1
    Try this: plnkr.co/edit/oUxthRRnqMkBzeXIRm1l?p=preview Commented Jan 27, 2016 at 5:21
  • Ohh..its my mistake. Commented Jan 27, 2016 at 5:22
  • where is $scope.shipping_status is defined or how you are setting value. Commented Jan 27, 2016 at 5:25

1 Answer 1

2

You haven't defined a shipping_status. That is why it equals to undefined. May be you have a typo in your variable name or intend to use $scope.shipping.

Change this

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

to

console.log('valid',$scope.shipping);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.