Home Can not get the drop down value using Angular.js
Reply: 2

Can not get the drop down value using Angular.js

subhra
1#
subhra Published in 2018-02-14 05:52:17Z

I am facing one issue. I can not select the right drop down value using Angular.js. I am explaining my code below.

<div class="form-group">
<label>Accept/Reject</label>
<select class="form-control" name="astatus"  id="astatus" ng-model="astatus">
<option value="">Select Accept/Reject</option>
<option value="1">Accept</option>
<option value="0">Reject</option>
</select>
</div>

The above is my select option. From the beginning I am setting the value like below.

$scope.astatus=0;

Then I selected the option from Reject to Accept and I checked the value like below.

console.log('status',$scope.astatus);//0

But here also I am getting the value as 0. Here I need to get different value as per selection where always I am getting the value as 0.

Sajeetharan
2#
Sajeetharan Reply to 2018-02-14 05:54:10Z

It works fine here. Use ng-change to get the selected value

DEMO

var app = angular.module('testApp',[]);
app.controller('testCtrl',function($scope){
  $scope.astatus=0;
  $scope.print = function(){
    console.log($scope.astatus);
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div class="form-group" ng-app="testApp" ng-controller="testCtrl">
<label>Accept/Reject</label>
<select class="form-control" name="astatus" ng-change="print()"  id="astatus" ng-model="astatus">
<option value="">Select Accept/Reject</option>
<option value="1">Accept</option>
<option value="0">Reject</option>
</select>
</div>

DeclanMcD
3#
DeclanMcD Reply to 2018-02-14 09:15:52Z

It is because your value of

$scope.astatus = 0;

should be

$scope.astatus = '0';

It is using string values whereas you are setting integer values. Set the value to a string and it will work

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.43961 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO