如何从角度下拉列表中获取值

时间:2014-04-14 07:49:31

标签: javascript angularjs

下拉

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);  
}

我无法获得选定的值。

请建议使用角度方式

1 个答案:

答案 0 :(得分:1)

您已使用datasource.value

将所选值绑定到data-ng-model='datasource.value'

尝试删除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>

只需使用$ watch即可观看datasource.value

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