angularjs-ng-options

How to filter a select with ng-options in Angular?

心已入冬 提交于 2019-12-03 04:45:43
I've written the following proof-of-concept of an Angular app that allows a person to vote for President of the US. <!DOCTYPE html> <html ng-app="ElectionApp""> <head> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.min.js"></script> <script> var ElectionApp = angular.module("ElectionApp", []); var ElectionController = ElectionApp.controller("ElectionController", [function () { // Pretend that this data came from an outside data-source. this.candidates = { "14837ac3-5c45-4e07-8f12-5771f417ca4c": { name: "Alice", gender: "female" },"333eb217-c8d1-4b94

Can't set selected value of ng-options

陌路散爱 提交于 2019-12-02 22:00:18
I am trying to populate a drop-down select options list and set a default selected value using ng-model and ng-options. I have the following code in my view: <select ng-model="thisTour.site" ng-options="site.name for site in siteList"></select> And in my controller: $scope.siteList = [ { id: 1, name: 'cycling'}, { id: 2, name: 'walking'}, { id: 3, name: 'holidays'} ] $scope.thisTour.site = { id: 2, name: 'walking'}; The list is getting populated with the correct 3 options from the siteList object, but it is not selecting walking by default as I would expect? Why not? Now, when I change this:

Based on country selected , need to populate state and city

徘徊边缘 提交于 2019-12-01 13:15:45
HTML: <label for="country">Country *</label> <select id="country" ng-model="statessource" ng-options="country for (country, states) in countries" ng-change="GetSelectedCountry()"> <option value=''>Select</option> </select> <label for="state">State *</label> <select id="state" ng-disabled="!statessource" ng-model="model.state" ng-options="state for (state,city) in statessource" ng-change="GetSelectedState()"><option value=''>Select</option> </select> <label for="city">City *</label> <select id="city" ng-disabled="!citiessource || !statessource" ng-model="city"><option value=''> Select</option>

Based on country selected , need to populate state and city

廉价感情. 提交于 2019-12-01 10:37:57
问题 HTML: <label for="country">Country *</label> <select id="country" ng-model="statessource" ng-options="country for (country, states) in countries" ng-change="GetSelectedCountry()"> <option value=''>Select</option> </select> <label for="state">State *</label> <select id="state" ng-disabled="!statessource" ng-model="model.state" ng-options="state for (state,city) in statessource" ng-change="GetSelectedState()"><option value=''>Select</option> </select> <label for="city">City *</label> <select id

How to disable option in Angular JS?

时光怂恿深爱的人放手 提交于 2019-12-01 01:04:27
I have ng-repeat option: <option ng-repeat="year in data.dateList.year" value="{{year.id}}" ng-disabled="(year.id < 2015) ? true : false"> You can see ng-disabled="(year.id < 2015) ? true : false" Why my option is not disabled if year.id less than 2015? This is my new code: <div class="itm" ng-repeat="a in range(num) track by $index"> <option ng-repeat="year in data.dateList.year" ng-disabled="(year.id) < formData.beginYear[$index]"> {{year.value}} </option> </div> You need to use ng-options here which has way to disable the options <select ng-model="year" ng-options="year.id disable when

Filter ng-options from ng-options selection

心不动则不痛 提交于 2019-11-30 03:58:15
I'm hoping to solve three problems... In my app page I have one select for states and another for counties. For states I have: <select ng-model="filter.stateID" ng-options="item.stateID as item.state for item in st_option"> </select> Data: [ { state="California", stateID="5"}, { state="Arizona", stateID="3"}, { state="Oregon", stateID="38"}, { state="Texas", stateID="44"}, { state="Utah", stateID="45"}, { state="Nevada", stateID="29"} ] For my County select I have: <select ng-model="filter.countyID" ng-options="item.countyID as item.county for item in co_option"> </select> Data: [ { county=

How to handle cascading/chained dropdowns using multiple ng-options

一笑奈何 提交于 2019-11-29 16:46:33
I am trying to get drop downs to only populate if the drop down above them has something selected. I had someone point me in the right starting direction with something like this. <select class="selectLevel0" ng-model='scope1' ng-change='scope1Change()' ng-options='obj.name for obj in array track by obj.id'> </select> <select class="selectLevel1" ng-model="scope2" ng-change='scope2Change()' ng-options='obj.name for obj in array2 track by obj.id' ng-hide='!scope1'> </select> <select class="selectLevel2" ng-model="scope3" ng-change='scope3Change()' ng-options='obj.name for obj in array3 track by

Filter ng-options from ng-options selection

走远了吗. 提交于 2019-11-29 01:37:10
问题 I'm hoping to solve three problems... In my app page I have one select for states and another for counties. For states I have: <select ng-model="filter.stateID" ng-options="item.stateID as item.state for item in st_option"> </select> Data: [ { state="California", stateID="5"}, { state="Arizona", stateID="3"}, { state="Oregon", stateID="38"}, { state="Texas", stateID="44"}, { state="Utah", stateID="45"}, { state="Nevada", stateID="29"} ] For my County select I have: <select ng-model="filter

How to handle cascading/chained dropdowns using multiple ng-options

只谈情不闲聊 提交于 2019-11-28 10:30:26
问题 I am trying to get drop downs to only populate if the drop down above them has something selected. I had someone point me in the right starting direction with something like this. <select class="selectLevel0" ng-model='scope1' ng-change='scope1Change()' ng-options='obj.name for obj in array track by obj.id'> </select> <select class="selectLevel1" ng-model="scope2" ng-change='scope2Change()' ng-options='obj.name for obj in array2 track by obj.id' ng-hide='!scope1'> </select> <select class=

Angularjs ng-options using number for model does not select initial value

筅森魡賤 提交于 2019-11-27 06:47:24
I'm trying to use ng-options with a <select> to bind a numeric integer value to a list of corresponding options. In my controller, I have something like this: myApp.controller('MyCtrl', function() { var self = this; var unitOptionsFromServer = { 2: "mA", 3: "A", 4: "mV", 5: "V", 6: "W", 7: "kW" }; self.unitsOptions = Object.keys(unitOptionsFromServer).map(function (key) { return { id: key, text: unitOptionsFromServer[key] }; }); self.selectedUnitOrdinal = 4; // Assume this value came from the server. }); HTML: <div ng-controller="MyCtrl as ctrl"> <div>selectedUnitOrdinal: {{ctrl