angularjs-ng-options

How to set preselected value in ng-option?

微笑、不失礼 提交于 2021-02-08 10:17:23
问题 I have id from the city that is supposed to be selected in dropdown list, but I can`t manage to preselect it. Should I select it from directive or is there any other way? <select ng-model="cityId" ng-options="city.name for city in cities"></select> 回答1: Edit your ng-options to this: city.id as city.name for city in cities if you fetch the cities and don't know the ID's you could say in your javascript success function (which returns the cities): $scope.cityId = the_cities[0].ID to set the

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

How can I get my compiled array from ng-options in a custom directive?

廉价感情. 提交于 2020-01-02 06:38:13
问题 I have a custom directive which I am decorating a <select ng-options=""> with as such... <select custom ng-model="selected" ng-options="o for o in values"> with custom as my directive and values being a simple array. Here is my implementation... <select custom ng-model="selected" ng-options="o for o in values"> <option value selected>uhh?</option> </select> app.directive('custom', [function() { return { scope: {}, link: function(scope, elem, attrs) { // how can I get my array of values here?

view pending status data in table by default

北城以北 提交于 2019-12-25 04:15:12
问题 <select class="form-control" id="selectrequest" ng-model="selectedrequest"> <option value="pending" > Pending </option> <option value="approved"> Approved </option> <option value="rejected"> Rejected </option> </select> <tr ng-repeat="mymodel in vm.modelname | filter:selectedrequest"> <td>{{mymodel.name}}</td> <td>{{mymodel.triggername}}</td> <td>{{mymodel.status}}<td> </tr> vm.modelname=[{ name:'Peter', triggername:'Peter1', status:pending },{ name:'Jack', trigger name:'Jack Hein', status

How to display sections within a select dropdown using AngularJS? [duplicate]

孤街浪徒 提交于 2019-12-24 19:35:46
问题 This question already has answers here : Angularjs: ng-options group by (3 answers) Working with select using AngularJS's ng-options (8 answers) How to add a header in dropdown list (with ng-options Demo) (4 answers) Closed last year . There is a select dropdown that currently displays a list of values (All Car Makes). The new requirement is to have sections within the same select dropdown, so that it shows a new set of values (Common Car Makes) under a section and along with the existing

How to use properly ng-change on angularjs dropdown element?

两盒软妹~` 提交于 2019-12-20 04:19:42
问题 I have this dropdownlist in my template: <div class="col-lg-5 col-md-5 col-sm-5 col-xs-5"> <div class="input-group input-group-sm"> <select class="form-control" data-ng-options="o.name for o in list.itemsStatus" data-ng-model="list.currentItemsStatus" ng-change="list.getItems(o.id)"> </select> </div> </div> Here is how is defined itemsStatus in controller: this.itemsStatus = [{ name: "all", id: 1 }, { name: "new", id: 2 }, { name: "toUpdate", id: 3 }]; when new item is selected I fire this

How to disable option in Angular JS?

白昼怎懂夜的黑 提交于 2019-12-19 04:47:43
问题 I have ng-repeat option: <option ng-repeat="year in data.dateList.year" value="{{year.id}}" ng-disabled="(year.id < 2015) ? true : false"> You can see ng-disabled="(year.id < 2015) ? true : false" Why my option is not disabled if year.id less than 2015? This is my new code: <div class="itm" ng-repeat="a in range(num) track by $index"> <option ng-repeat="year in data.dateList.year" ng-disabled="(year.id) < formData.beginYear[$index]"> {{year.value}} </option> </div> 回答1: You need to use ng

Angular JS - get selected text as ng model (without ng-options)

扶醉桌前 提交于 2019-12-13 23:51:28
问题 In my code behind, I fill up a DropDownList as follows (using VB) ddlCountries.DataSource = dt ' dt is DataTable with columns "CountryCode" and "CountryName" ddlCountries.DataTextField = "CountryName" ddlCountries.DataValueField = "CountryCode" ddlCountries.DataBind() ddlCountries.Attributes.Add("ng-model", "CountryName") Then client side, I have a select tag, which is filled with options from server side as below: <select ng-model="CountryName"> <option value="IN">India</option> <option

ng-options Set ng-model value as selected item in blank list

大城市里の小女人 提交于 2019-12-13 18:11:56
问题 I have a different case here with ng-options I have two modes for my app. New mode and Edit mode I have SELECT input types for DISTRICTS and VILLAGES. The VILLAGES select is populated based on DISTRICT selection using ng-change event of DISTRICT select. This works fine in NEW mode. But when in EDIT mode, the DISTRICT is correctly showing the value of ng-model. But the VILLAGE select input item is not showing the ng-model value. This is because, the village select does not have any items

Angularjs how to set the default value for select

孤街醉人 提交于 2019-12-13 14:24:32
问题 I have the following object: defaults = { 0 : { id : 10, value : "string 1" }, 1 : { id : 22, value : "string 2" } } I want to iterate over this object and display it as a select box. <select ng-model="selectedValue" ng-options="obj.id as obj.value for obj in defaults"> <option value="">---Select option-----</option> </select> What I'm trying to achieve is to select 'string 2' by default. But it does not work. The problem I have is the fact the selectedValue is a string: $scope.selectedValue