ng-options

AngularJS drop down (ng- options) not binding - string to object (initial selection)

淺唱寂寞╮ 提交于 2019-12-03 08:01:16
I am having a problem binding data retrieved from the server to a drop down list. The main issue I think is the fact that the comparison is done on differing object types. For example: 1. The object returned from the server contains a currency code string. we want this to be bound to an item in the dropdown list "baseCurrencyCode":"GBP" The view model returns the list of currencies.. These are returned as a list of currency objects with different properties {"currencies":[{"id":1,"rateId":0,"abbreviation":"AFN","description":"Afghani","rate":0.0,"rateDescription":null,"languageCode":"en-gb",

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

心已入冬 提交于 2019-12-03 04:45:43
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.candidates = { "14837ac3-5c45-4e07-8f12-5771f417ca4c": { name: "Alice", gender: "female" },"333eb217-c8d1-4b94

angularjs select required not working ng-options

巧了我就是萌 提交于 2019-12-03 04:25:00
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. 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 ['Mazda2','Maxda3']" required> <option></option> </select> You can also try ng-required="true" (it works on the

angular select 用法

匿名 (未验证) 提交于 2019-12-03 00:37:01
angular select 用法1: 数组 // 循环数组 $scope.books = [ { "id" : 1 , "name" : "Chinese" , "number" : "2" }, { "id" : 2 , "name" : "English" , "number" : "2" }, { "id" : 3 , "name" : "French" , "number" : "1" } ] // html < select ng-model= "ss" ng-options = "book.id as book.name for book in books" > <option value = "" >--请选择--</option> </ select > 用法2: 对象 // 循环对象 $scope.books = { "Chinese" : 2 , "English" : 2 , "French" : 1 }; // html < select ng -model = "ss" ng -options = "value for (value, key) in books" > < option value = "" >-- 请选择 --< /option > < / select > **用法3:**optgroup分组 // 循环对象 $scope.books

How to assign selected option's text to another model while using ng-options?

依然范特西╮ 提交于 2019-12-02 04:28:43
问题 I can create a select tag and place data inside it. I can assign that select's selected option to a model but can't assign its text to another model. Here is example below and jsFiddle link html: <div ng-app> <div ng-controller="DemoCtrl"> <select ng-model="customerId" ng-options="item.id as item.name for item in content" ng-change="customerName = item.name"> </select> <br/> <input disabled="disabled" type="text" ng-model="customerId"/> <input disabled="disabled" type="text" ng-model=

Ng-Options Expression Repeatedly Called

三世轮回 提交于 2019-12-02 02:16:20
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 I would like to fix my loop. My html: <select ng-options="theorderdate as theorderdate for

how to bind default value to select using ng-model using AngularJS V1.6

醉酒当歌 提交于 2019-12-02 01:42:30
问题 <select ng-model="machineSelected" ng-options="machine._id as machine.name for machine in machineList" ng-change="onChangeMachine(machineSelected)" ng-disabled="!mineSelected"> <!--<option value=""></option>--> <option value="">Select</option> </select> When I add $scope.machineSelected = ""; dynamically wherever in the controller, option in drop-down should set as "Select", but it is not updating. 回答1: Use null or undefined , not an empty string, as the "not selected" value. That's what the

how to bind default value to select using ng-model using AngularJS V1.6

江枫思渺然 提交于 2019-12-02 00:48:26
<select ng-model="machineSelected" ng-options="machine._id as machine.name for machine in machineList" ng-change="onChangeMachine(machineSelected)" ng-disabled="!mineSelected"> <!--<option value=""></option>--> <option value="">Select</option> </select> When I add $scope.machineSelected = ""; dynamically wherever in the controller, option in drop-down should set as "Select", but it is not updating. Use null or undefined , not an empty string, as the "not selected" value. That's what the docs say: Optionally, a single hard-coded <option> element, with the value set to an empty string, can be

How to assign selected option's text to another model while using ng-options?

梦想与她 提交于 2019-12-01 23:09:17
I can create a select tag and place data inside it. I can assign that select's selected option to a model but can't assign its text to another model. Here is example below and jsFiddle link html: <div ng-app> <div ng-controller="DemoCtrl"> <select ng-model="customerId" ng-options="item.id as item.name for item in content" ng-change="customerName = item.name"> </select> <br/> <input disabled="disabled" type="text" ng-model="customerId"/> <input disabled="disabled" type="text" ng-model="customerName"/> <!-- i'm trying to get customer name and assign that on to my model --> </div> </div> js:

AngularJS problems with ng-options selected value

倾然丶 夕夏残阳落幕 提交于 2019-12-01 22:49:15
问题 I'm facing a strange problem when using ng-options with AngularJS. My scenario is pretty straight forward: Bind a value with ng-model to be the selected option Load the values of the 'select' from a backend Bind the loaded values to the 'select' My objects loaded from the backend is a key/value like: { Value: "my_value", Name: "my_name" } And everything works fine... Until Name and Value are the same. Then angular won't bind the selected value correct anymore. I have created this plunker: