admin管理员组文章数量:1415664
I have an object like bellow:
var data = {
BCS: ['a', 'b', 'c', 'd'],
HND: ['e', 'f', 'g', 'h'],
LMU: ['i', 'j', 'l', 'm']
};
And Bellow is my controller
function getDivision($scope) {
$scope.divisions = data;
}
And this is model
<div ng-app>
<div ng-controller='getDivision'>
<select ng-model="key" ng-options="key for (key , val) in divisions" ng-change="update()"></select>
<select ng-model="divisionValues" ng-options="value for value in key"></select>
</div>
</div>
This is JsFiddle
How can i get first selected value and parse it to the controller ?
I have an object like bellow:
var data = {
BCS: ['a', 'b', 'c', 'd'],
HND: ['e', 'f', 'g', 'h'],
LMU: ['i', 'j', 'l', 'm']
};
And Bellow is my controller
function getDivision($scope) {
$scope.divisions = data;
}
And this is model
<div ng-app>
<div ng-controller='getDivision'>
<select ng-model="key" ng-options="key for (key , val) in divisions" ng-change="update()"></select>
<select ng-model="divisionValues" ng-options="value for value in key"></select>
</div>
</div>
This is JsFiddle
How can i get first selected value and parse it to the controller ?
Share Improve this question asked May 16, 2014 at 3:50 underscoreunderscore 6,9077 gold badges43 silver badges81 bronze badges 4- @MarcKline did you my fiddle ? – underscore Commented May 16, 2014 at 4:11
- @MarcKline see the update fiddle jsfiddle/cQ99H/2 – underscore Commented May 16, 2014 at 4:13
- @MarcKline NOOOO.IT showing selected array.I need the key.When selected HND i need to parse HND to the controller – underscore Commented May 16, 2014 at 4:16
- e chat.stackoverflow./rooms/17/javascript – underscore Commented May 16, 2014 at 4:18
2 Answers
Reset to default 1Your expressions should look like the following:
<select ng-model="key"ng-options="key as key for (key, val) in divisions"
ng-change="update()"></select>
<select ng-model="divisionValues"
ng-options="value for value in divisions[key]"></select>
This bination will allow your users to select from the keys of data
, and once they do, the second select
box will contain the four letters associated with them in the associated value array.
The expressions are tricky and hard to understand at first, but if you read the docs a few times and experiment, it will all make sense.
Working Fiddle
You have to pass the key to the update method like ng-change="update(key)"
Working Demo
html
<div ng-app>
<div ng-controller='getDivision'>
<select ng-model="key" ng-options="key as key for (key, val) in divisions" ng-change="update(key)"></select>
<select ng-model="divisionValues" ng-options="value for value in divisions[key]"></select>
</div>
</div>
script
var data = {
BCS: ['a', 'b', 'c', 'd'],
HND: ['e', 'f', 'g', 'h'],
LMU: ['i', 'j', 'l', 'm']
};
function getDivision($scope) {
$scope.divisions = data;
$scope.update = function (a) {
console.log(a);
}
}
本文标签: javascriptget selected value in angular ngoptionStack Overflow
版权声明:本文标题:javascript - get selected value in angular ng-option - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745239704a2649252.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论