ng-options

Dynamic dropdown select in AngularJS not working

半腔热情 提交于 2019-12-12 12:27:29
问题 I am practicing with Angular and want to give users the option to choose from 3 dropdown select menus. The third menu should be dynamic depending on the selection from the previous two menus. My html: // First dropdown menu, static <select ng-model="selectedLetter" ng-change="setColorSelection()" ng-options="letter as letter for letter in letters"> </select> <br> // second dropdown menu, static <select ng-model="selectedNumber" ng-change="setColorSelection()" ng-options="number as number for

Why ng-model does not update controller value select?

那年仲夏 提交于 2019-12-12 10:51:53
问题 This is the code HTML: <div ng-controller="SelectCtrl"> <p>selected item is : {{selectedItem}}</p> <p> age of selected item is : {{selectedItem.age}} </p> <select ng-model="selectedItem" ng-options="item.name for item in items"> </select> </div> This is the code AngularJS: var app = angular.module('myApp', []); app.controller('SelectCtrl', function($scope) { $scope.items = [{name: 'one', age: 30 },{ name: 'two', age: 27 },{ name: 'three', age: 50 }]; $scope.selectedItem = $scope.items[0];

angularjs ng-options nested json data

寵の児 提交于 2019-12-12 10:11:06
问题 I am using AngularJS for my web app. My objective is to have two dropdowns list using ng-options . The first dropdown showing the country list The other gives the language preferences for the selected country Being still new to AngularJS, I am able to display the data but the entire object is displayed as a single option, I am unable to split each data. Kindly find the code below that I used. HTML <select ng-model="selectedRegion" ng-options="region.countryName for region in eyebrow

ng-options Default Value for Angular Dropdown

纵饮孤独 提交于 2019-12-12 03:36:24
问题 I have two dropdowns, one is dependent on the other. I originally had my code using ng-repeat but read that it is more efficient to use ng-options. However, in switching over, I can't use ng-selected for the default any longer. I've looked at different methods of setting the default option in ng-options but they use either <option value="">Select Something Here</option> for a customized option or selecting straight from the dataset. However my value will be changing. Here is a plunker missing

angularjs select with filter leaves first line empty but not when filter is applied upfront

坚强是说给别人听的谎言 提交于 2019-12-12 02:01:37
问题 I am a bit lost as to why my ng-options is once again returning an empty line with a filter. Please have a look at this plunker The idea is to display in a dropdown list an org chart which is based on a tree-structured object. To do this I have built a service that flattens the tree into a 1 dimensional object. I use this service inside a filter that is called in my ng-option. <select ng-model="treeValue1" ng-init="treeValue1 = fields[0]" class='form-control' ng-options="element as element

Problems when using ng-options and ng-switch together

Deadly 提交于 2019-12-12 01:22:16
问题 I have an issue when I am trying to use ng-options and ng-switch together in AngularJS to dynamically change what content is put on the page for a widget builder I am working on. I have two issues I am experiencing: 1. I can't seem to set ng-option to default to the value being set by the model from the json it displays. 2. When I change the ng-option field the switch below breaks and no longer showes the correct code. Here is the code: <div ng-app=""> <div data-ng-controller=

How to count unique results based on a particular properties within ng-options

这一生的挚爱 提交于 2019-12-12 00:34:06
问题 I'm working with AngularJS and trying to create a filter to search properties. I've got a select box like this: <select class="selectBox" multiple="multiple" ng-model="selectedSubArea" ng-options="property.SubArea as (property.SubArea + ' ('+ filtered.length +')') for property in filtered = (properties | unique:'SubArea') | orderBy:'SubArea'"> </select> This is the unique function: myApp.filter('unique', function() { return function(input, key) { var unique = {}; var uniqueList = []; for(var

How can I disable options for different selects in order to have always different options selected?

这一生的挚爱 提交于 2019-12-11 19:39:38
问题 I'm working with Angularjs. HTML: <select name="questionId1" ng-model="abCtrl.form.questionSel.q1" ng-options="question.val for question in abCtrl.form.questions track by question.index"></select> <select name="questionId2" ng-model="abCtrl.form.questionSel.q2" ng-options="question.val for question in abCtrl.form.questions track by question.index"></select> I'd like the option the user selects will be disabled for the other selection and vice versa 回答1: Replacing ng-options with ng-repeat -ed

How to choose default time value in a select box with ng-options

不羁的心 提交于 2019-12-11 16:25:32
问题 I have a form with select boxes to choose a business' working hours. I want to choose 9:00 am as the default value for the first box, and 5:00 pm as the default value for the second box. Here is the JSfiddle For example, I have <select ng-options="hour as (hour | date: 'shortTime') for hour in hours" ng-model="start_time" ng-change="update(start_time, $index, 1)"> If in my app.js I set $scope.start_time equal to a Date object initialized to the current date and time as 9:00 am, the default

AngularJS: ngMessages not working with ng-options in select

谁都会走 提交于 2019-12-11 15:54:35
问题 I have seen few answers which were working for ng-repeat, but with ng-options I am facing issue. Problem : Want to show the error message required if the dropdown is touched and nothing is selected, I am able to do this with input fields. JS CODE $scope.personMap = [{ name:"Abc", id:"a"}, { name:"XYZ", id:"b"}, { name:"FGH", id:"c"}, { name:"TY", id:"d"} }] HTML <select name="inpName" ng-model="person.name" ng-options="i as i.name for i in personMap track by i.id" required> <option value=""