ng-options

Prevent multiple select to have the same value

北城以北 提交于 2020-12-13 04:24:06
问题 What it should do I want to prevent the user to be able to select twice the same option in multiple <select> having the same options. What it is doing When selecting a value on the first dropdown, the second won't have the option visible (great). But when selecting a value on the second dropdown (and the first one already have one), it's deleting all the selections. I end up with a selection [null, null] . Am I missing something? JSFiddle var app = angular.module('App', []); app.controller(

Prevent multiple select to have the same value

眉间皱痕 提交于 2020-12-13 04:24:05
问题 What it should do I want to prevent the user to be able to select twice the same option in multiple <select> having the same options. What it is doing When selecting a value on the first dropdown, the second won't have the option visible (great). But when selecting a value on the second dropdown (and the first one already have one), it's deleting all the selections. I end up with a selection [null, null] . Am I missing something? JSFiddle var app = angular.module('App', []); app.controller(

angularjs: ng-select和ng-options

只谈情不闲聊 提交于 2020-02-17 14:46:08
angular.js有一个很强大的指令: ng-select 它可以帮助你通过数据模型来创建select元素.它很好的支持了select标签的语法,但是却有点坑. 假设有如下一段json数据: 复制代码 { "myOptions": [ { "id": 106, "group": "Group 1", "label": "Item 1" }, { "id": 107, "group": "Group 1", "label": "Item 2" }, { "id": 110, "group": "Group 2", "label": "Item 3" }, } $scope.myOptions = data.myOptions; 复制代码 这段数据很简单: 我有一些分组,每个分组都包含自己的一些选项.如果要直接用这些数据创建select元素是很麻烦的.所以,我把代码重构成下面这样: angularjs会自动进行分组 <select ng-model="myOption" ng-options="value.id as value.label group by value.group for value in myOptions"> <option>--</option> </select> ng-model的值会指向select元素的当前选中项的value值. ng

ng-options用法详解

北城以北 提交于 2020-02-17 14:45:50
原文地址: http://www.ncloud.hk/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/ng-options-usage/ ng-options属性可以在表达式中使用数组或对象来自动生成一个select中的option列表。ng-options与ng-repeat很相似,很多时候可以用ng-repeat来代替ng-options。但是ng-options提供了一些好处,例如减少内存提高速度,以及提供选择框的选项来让用户选择。当select中一个选项被选择,该选项将会被绑定到ng-model。如果你想设一个默认值,可以像这样: $scope.selected = $scope.collection[ 3 ] 。 之前一直在用ng-repeat就见到过track by,没有去了解它的用法,这次了解了一下。track by主要是防止值有重复,angularjs会报错。因为angularjs需要一个唯一值来与生成的dom绑定,以方便追踪数据。 例如:items=[“a”,“a”,“b”],这样ng-repeat=“item in items”就会出错,而用ng-repeat=“ (key,value) in items track by key ”就不会出现错误了。 ng-options一般有以下用法: 对于数组: label for value

select won't show default value when list is read from server angularjs

只谈情不闲聊 提交于 2020-01-06 04:13:05
问题 I have this below select which won't show the default value when statuslist is read from the server through a http call in IE9. If statuslist values are set in the controller itself then default value show up fine. <select id="status" class="form-control" ng-init="selectedStatus = statuslist[0]" ng-model="selectedStatus" ng-options="status for status in statuslist"> </select> Default value is displayed in the dropdown if I do this $scope.statuslist = [ "New", "Management Review" ] but not if

Angular ng-options - Is there a way to add an option when the model contains a value not present in the options list?

纵饮孤独 提交于 2020-01-04 14:39:48
问题 When the model, eyeColorUnknown, contains a value that is not present in the options Angular creates an option with a value of "?" and blank for the visual description as shown below. <select ng-model="eyeColorUnknown" ng-options="option.val as (option.desc + ' - ' + option.val) for option in options | orderBy:'desc'" class="ng-pristine ng-valid"> <option value="?"></option> <option value="0">Blue - 001</option> <option value="1">Brown - 003</option> <option value="2">Green - 002</option> <

angularjs ng-options select from nested json array

寵の児 提交于 2020-01-02 10:04:31
问题 I have a json defined in my scope like $scope.People = [ { "firstName":"John", "lastName":"Doe", "Choices":[ { "Name":"Dinner", "Options":[ { "Name":"Fish", "ID":1 }, { "Name":"Chicken", "ID":2 }, { "Name":"Beef", "ID":3 } ] }, { "Name":"Lunch", "Options":[ { "Name":"Macaroni", "ID":1 }, { "Name":"PB&J", "ID":2 }, { "Name":"Fish", "ID":3 } ] } ] }, { "firstName":"Jane", "lastName":"Doe" } ]; Wanted to list all the choices options name (without duplicates) in a single drop down box using

Using ng-options with nested arrays

放肆的年华 提交于 2020-01-02 07:43:09
问题 I am getting some data back from my server. The data structure is: [{"sectorName1": "nameHere", "subSectors": ["sub1", "sub2", "sub3"] }, {"sectorName2": "nameHere", "subSectors": ["sub1", "sub2", "sub3"] }] I am trying to display each sectors subSectors with ng-options. So when some uses the dropdown they will see all the subsectors. I have tried this but doesn't seem to work: <select id="selectSubSector" class="form-control" name="subSector" ng-model="item" ng-options="sec for sec in

Ng-Options Expression Repeatedly Called

回眸只為那壹抹淺笑 提交于 2019-12-31 03:22:07
问题 I am having multiple issues with my <select> element in angular and am trying to understand what is going on. My first step is to understand why the multiple console.log() messages I have put in for debugging repeatedly appear in the console, as in, instead of the message appearing once like I would expect, they appear an infinite number of times, as if part of an infinite loop. Is this how a function called from an ng-options is supposed to behave? If so, I don't understand why, if not, then