ng-options

ngOptions two level object display

不羁的心 提交于 2019-12-05 07:52:43
I have this structure: model = [ { name: 'name1', items: [ { name: 'subobj1' }, { name: 'subobj2' }] }, { name: 'name2', items: [ { name: 'subobj1' }, { name: 'subobj2' }] }, .... ] Question is: How do I write ngOptions attrbiute to output this object like this?: <select> <optgroup label="name1"> <label>subobj1</label> <label>subobj2></label> </optgroup> .... </group> Also - ngRepeat is not an option. I have to do this ngOptions alone for plugin being used to work. Ilan Frumer ngOptions doesn't support multi-dimensional arrays. You must flatten your array first. Read more in this answer . I

AngularJs - ng-options not binding after ajax call

落爺英雄遲暮 提交于 2019-12-05 05:44:40
I try to change the selected index of ng-options after ajax call, but it won't change. //Html Section... <select id="fooId" ng-model ="foo.formula" ng-options="formulas as name for (formulas, name) in the_formula"></select> //End Html Section... //js file... //get list of formula from server... TheSource.Get.then(function(response){ $scope.the_formula = response.the_formula; }); //do something awesome, then.. //binding data from server... TheData.Get.then(function(response){ //binding the data to view... //all of the element is binding, except the ng-options part.. $scope.foo = response; //not

AngularJS ng-options to exclude specific object

℡╲_俬逩灬. 提交于 2019-12-05 03:55:26
I'm using angular ng-options to show a with several options as the choices of parent category of the current category, basically these options contain all the existing categories, and I need to exclude the current category from ng-options, which quite make sense because a category cannot be the parent category of itself. So how do I do that? Currently I have the following code: <tr ng-repeat="category in allCategories"> <th ng-bind="category.name"></th> <th> <select ng-options="everyCategory.name for everyCategory in allCategories"> <option value="">Select parent category</option> </select> <

How do I use ngOptions with a string that contains HTML entities?

对着背影说爱祢 提交于 2019-12-05 03:03:51
I'm using ngOptions to built a selection menu but one of my labels has an HTML entity in it & . The label shows up as Books & Stuff not Books & Stuff . My jade is this: select(ng-show="isType === 'select'", id="{{id}}", ng-model="model", ng-options="o.id as o.label for o in options") How can I get HTML entities to display properly? Update I'm trying the answer by sal: select(ng-show="isType === 'select'", id="{{id}}", ng-model="model") option(ng-repeat="o in options", ng-bind-html="o.label", value="{{o.id}}") An this displays the correct html entity but the correct option is not selected any

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

家住魔仙堡 提交于 2019-12-04 10:00:49
问题 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

How to use ng-click on ng-option( or other way to assign value)

最后都变了- 提交于 2019-12-03 23:44:36
问题 How to use ng-options. $scope.fieldTable = [ { filed:"text", title:"Global" }, { field: "relatedentity", title: "Entity" }, { field:"title", title:"Title" }, { field: "content", title: "Content" } ] I want to build a which use the title as displayed and when select something, popout a alert window which display the according field. The initial selection is { filed:"text", title:"Global" } Can anyone help? 回答1: var app = angular.module('stack', []); app.controller('MainCtrl', function($scope)

Angular injects “string:” before value in ng-options

柔情痞子 提交于 2019-12-03 21:51:20
问题 I have a ng-options list defined with a HTML select element such as: <select required="required" ng-model="vm.selectedOption" ng-options="item.name as item.label for item in vm.options"> <option value="">Select an option</option> </select> This however results in the following HTML: <option value="string:VALUE" label="Option Name">Option Name</option> I am using Angular version 1.4.8, does anyone have a solution how to solve the string: issue or at least can explain to me why this is

AngularJS dropdown not showing selected value

北慕城南 提交于 2019-12-03 17:50:19
问题 Am facing problem in displaying selected value in angular dropdown. it works when i give like this $scope.selectedItem = $scope.items[1]; not working, if i give directly that value $scope.selectedItem = { name: 'two', age: 27 }; HTML : <html ng-app="app"> <body> <div ng-controller="Test"> <select ng-model="selectedItem" ng-options="item.name for item in items"> </select> </div> </body> </html> JS : var app = angular.module('app',[]); app.controller('Test',function($scope){ $scope.items = [

angularjs select required not working ng-options

两盒软妹~` 提交于 2019-12-03 14:37:53
问题 I am trying to ensure a user selects a value from a select box before submitting the form. This works correctly with static options; it however fails when populating the options via a model using ng-options Example http://plnkr.co/edit/wRqSCNskLo5c48jy4nQf I am using AngularJS 1.2.9 Thank you in advance. 回答1: In your example changing the data bound select to the following fixes the required directive. I'm not sure why exactly. <select ng-model="selectedValue1" ng-options="opt for opt in [

AngularJS - setting selected value of dropdown does not work

时光怂恿深爱的人放手 提交于 2019-12-03 13:06:18
I made a fiddle replicating my problem here: http://jsfiddle.net/U3pVM/2840/ As the title suggests, I can't set the selected value of a select populated using ng-options. I have searched and tried all possible solutions that I found. Any help or suggestions would be appreciated! HTML <div ng-app> <h2>Todo</h2> <div ng-controller="TodoCtrl"> <select ng-model="ddlRooms" ng-options="r.id as r.Name for r in Rooms"> </select> {{$scope.test}} </div> </div> Angular function TodoCtrl($scope) { $scope.Rooms = [{ Name: 'Toddler', id: 1 },{ Name: 'other', id: 2 }]; $scope.options = [{ Name: 'other', id: