ng-options

AngularJs conditional display for ng-options

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 12:10:47
问题 I've been searching for a few hours now and I can't seem to find the answer for my problem anywhere. I remember that I was able to implement it before but for some reason I lost the code and I can't seem to remember what I did to make it work. I'm trying display data from an array in a select box using ng-options. That one I have no problems with. What I need to implement is that only certain array values will be displayed/included in the select box. My data is as follows: $scope.chartList =

How to disable a <option> of select element when using AngularJS ng-options?

一曲冷凌霜 提交于 2019-11-29 10:19:33
Is there a way to disable an option in a select element when we populate options with ng-options in AngularJS? Like this: http://www.w3schools.com/tags/att_option_disabled.asp You can do it by adding ng-disabled to each <option> tag, but is there a way to do it if we are using the ng-options directive in the select tag? towr One way to do this is, to forget using ng-options on the select element, and add the options in with ng-repeat , then you can add a ng-disabled check on each option . http://jsfiddle.net/97LP2/ <div ng-app="myapp"> <form ng-controller="ctrl"> <select id="t1" ng-model=

angularJS - add a Static option with ng-options

落花浮王杯 提交于 2019-11-29 04:29:09
I am using ng-options to print all the options for a form in my angular app. I get the value directly from my database which gives me a list of countries: <select ng-options="country.country for country in countries" ng-model="selectedCountry" ng-change="updateSelectedCountry(selectedCountry)" class="form-control"> Here when the page is loaded, the select doesnt show anything, i.e. there is no placeholder whereas I'd like to print a static value like "anywhere" without having to add it in my "countries" list. I have tried this: <select ng-options="country.country for country in countries" ng

Disabled selected item in Angular for other Select Option Fields of the same Items

假装没事ソ 提交于 2019-11-29 02:45:49
I've been struggling on this for a while... I'm currently using Angular. Let's say we have five select option fields and that we are iterating through the same list for each one. Our options are: $scope.items = [one, two, three, four, five]; If I choose one, how would I disable the selected option for the remaining select option fields? And if I go to another select option field and select an available item, it then disables that item for all the other fields. Any help or even guidance on how to do this would be appreciated. Thanks There are two possible solutions that you may want, and it

Angularjs - dynamic ng-options

我的未来我决定 提交于 2019-11-29 01:49:42
For the need of a directive i'm writing, i have to construct dynamically the ng-options expression. Here is what i tried. In my directive: // ... scope.labelProperty = 'name'; scope.selectOptions = "l." + scope.labelProperty + " for l in list"; In my html template: <select class="form-control" ng-model="selected.available" ng-options="{{ selectOptions }}" multiple size="5"></select> This results in ng-options taking the correct expression "l.name for l in list" but options dont display. Please, any idea ? Change your code to look like this (use javascript to pick your property): // ... scope

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

AngularJS ngOptions sort array

懵懂的女人 提交于 2019-11-28 22:52:09
I have been trying to use ng-options to display an array of fonts in a select sorted alphabetically by the value of the items in the array. HTML <select ng-options="font for font in webfonts | orderBy:'font'" name="fonts"> <option value="">Choose a font</option> </select> JS $scope.webfonts = [ 'Abel', 'Crafty Girls' , 'Lato' , 'Average', 'Corben', 'Quicksand', ... ]; I've tried changing the value in orderBy and other things. I've read through the documentation and all comments. What am I missing? Is this supposed to only work on objects? This is what you need to do: <select ng-model="selected

How to ng-translate inside select box option in angularjs

喜夏-厌秋 提交于 2019-11-28 16:58:23
How do I apply ng-translate to translate options inside a select box. For example: Template: <select class="form-control" ng-model="me.gender" ng-options="gender.name for gender in genders"> </select> Controller: $scope.genders = [{code: "M", name:"TXT_MALE"}, {code: "F", name:"TXT_FEMALE"}] enUS.json: { "TXT_MALE": "Male", "TXT_FEMALE": "Female", } I tried adding filter like ng-options="gender.name for gender in genders | translate" but obviously it was adding filter to $scope.genders array instead of single element I tried writing own filter (I am new to this) filter('translateArrayObj', ['

Setting selected values for ng-options bound select elements

折月煮酒 提交于 2019-11-28 16:32:16
Fiddle with the relevant code: http://jsfiddle.net/gFCzV/7/ I'm trying to set the selected value of a drop down that is bound to a child collection of an object referenced in an ng-repeat. I don't know how to set the selected option since I can't reference the collection it's being bound to in any way that I'm aware of. HTML : <div ng-app="myApp" ng-controller="SomeController"> <div ng-repeat="Person in People"> <div class="listheader">{{Person.firstName}} {{Person.lastName}}</div> <div class="listitem" ng-repeat="Choice in Person.Choices"> {{Choice.Name}}: <select ng-model="Choice

How to add a header in dropdown list (with ng-options Demo)

白昼怎懂夜的黑 提交于 2019-11-28 14:22:09
I want to create a dropdown list in AngularJS from a JSON file. How do I add a header for similar list items in my dropdown? For example: Malaysia (add the header here) --sunway --subang --petaling jaya --shah alam --Klang --Subang Jaya --Setia alam --sunway lagoon Japan (add the header here) --tokyo --osaka --kyoto --shinsabashi --shinagawa Presuming your json looks something like this $scope.dropdown = [ { name:'Malaysia', items: [ {name: 'sunway', value: 1}, {name: 'subang', value: 2}, {name: 'petaling jaya', value: 3} ] }, { name:'Japan', items: [ {name: 'tokyo', value: 4}, {name: 'osaka',