Prashobh
Prashobh

Reputation: 9542

How to get values from angular dropdown

Drop down

HTML

<select data-ng-model='datasource.value' ng-options='sourcetype.dataSourceType as sourcetype.dataSourceDesc for sourcetype in sourcetypes' data-ng-change="getAccountCredentials(sourcetype);">
    <option disabled value="" selected>Choose One</option>
</select>

JavaScript

$scope.getAccountCredentials = function(data){      
    console.log(data);  
}

I am not able to get selected values .

Please suggest angular way to do this

Upvotes: 0

Views: 192

Answers (1)

Khanh TO
Khanh TO

Reputation: 48972

You're already binding your selected value to datasource.value with data-ng-model='datasource.value'

Try removing data-ng-change="getAccountCredentials(sourcetype);":

<select data-ng-model='datasource.value' ng-options='sourcetype.dataSourceType as sourcetype.dataSourceDesc for sourcetype in sourcetypes'>
    <option disabled value="" selected>Choose One</option>
</select>

And just use $watch to watch your datasource.value

$scope.$watch("datasource.value",function(newValue){      
    console.log(newValue);  
});

Upvotes: 1

Related Questions