ng-options

angularJS - add a Static option with ng-options

送分小仙女□ 提交于 2019-11-27 18:20:01
问题 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

ng-options and unique filter not displaying angular.js

余生颓废 提交于 2019-11-27 16:17:05
In my javascript I have an array $scope.quoteList = [ { select: false, laymansDescription: "Nathan", quoteNumber: "ING-70440-21", version: "02", quoteDate: "Feb 5,2013", expirationDate: "Aug 5,2013", internalNotes: "This quote is using test data", }, { select: false, laymansDescription: "Mitch", quoteNumber: "ING-70440-01", version: "02", quoteDate: "Feb 5,2013", expirationDate: "Aug 5,2013", internalNotes: "This quote is using test data", }, { select: false, laymansDescription: "Stephen", quoteNumber: "ING-70440-01", version: "02", quoteDate: "Feb 5,2013", expirationDate: "Aug 5,2013",

Angularjs - dynamic ng-options

跟風遠走 提交于 2019-11-27 16:13:57
问题 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.

ng-options with simple array init

余生颓废 提交于 2019-11-27 10:24:18
I'm a little bit confused with Angular and ng-options . I have a simple array and I want to init a select with it. But, I want that options value = label. script.js $scope.options = ['var1', 'var2', 'var3']; html <select ng-model="myselect" ng-options="o for o in options"></select> What I get: <option value="0">var1</option> <option value="1">var2</option> <option value="2">var3</option> What I want: <option value="var1">var1</option> <option value="var2">var2</option> <option value="var3">var3</option> So I tried: <select ng-model="myselect2" ng-init=0 ng-options="options[k] as v for (k,v) in

How to ng-translate inside select box option in angularjs

╄→尐↘猪︶ㄣ 提交于 2019-11-27 10:07:25
问题 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

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

↘锁芯ラ 提交于 2019-11-27 08:34:21
问题 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 回答1: Presuming your json looks something like this $scope.dropdown = [ { name:'Malaysia', items: [ {name: 'sunway', value: 1}, {name: 'subang', value: 2}

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

How to set default value in ng-options

ε祈祈猫儿з 提交于 2019-11-27 05:55:28
问题 I can set a dropdown list with default value in angularjs as, <select name="repeatSelect" id="repeatSelect" ng-model="repeatSelect" ng-init=" repeatSelect = data[0].id"> <option ng-repeat="option in data" value="{{option.id}}">{{option.name}}</option> </select> How can I achieve the same using ng-options ? I treid with, <select name="repeatSelect" id="repeatSelect" ng-model="repeatSelect" ng-init=" repeatSelect = option.id" ng-options="option.name for option in data track by option.id"> <

Angularjs: ng-options group by

。_饼干妹妹 提交于 2019-11-27 05:14:28
I have this one level tree situation: <select ng-model="tipost" ng-options="tip.DESC group by tip.TIPIS for tip in tipall"><br> </select> where the json is: [ {"ID":"1", "IDPARENT":"0", "TIPIS":"", "DESC":"GroupName1"}, {"ID":"2", "IDPARENT":"1", "TIPIS":"GroupName1", "DESC":"CHILDNAME1"}, {"ID":"3", "IDPARENT":"0", "TIPIS":"", "DESC":"GroupName2"} ] the problem is that this creates the optgroups with their children but repeats the roots too: - GroupName1 - GroupName2 [ GroupName1 ] - CHILDNAME1 [ GroupName2 ] i want to produce: [ GroupName1 ] - CHILDNAME1 [ GroupName2 ] The grouping doesn't

ng-change get new value and original value

青春壹個敷衍的年華 提交于 2019-11-26 19:40:49
I'm using ng-options to select values from a pulldown. I'd like to be able to compare the old value to the new value. ng-change works well for grabbing the new value of the pull down, but how can I get both the new value and the original value? <select ng-change="updateValue(user)" ng-model="user.id" ng-options="user.id as user.name for user in users"></select> For instance, let's say I wanted the controller to log, "Your former user.name was BILL, your current user name is PHILLIPE." db-inf With an angular {{expression}} you can add the old user or user.id value to the ng-change attribute as