Home » Uncategorized » select angularjs

select angularjs

Angularjs provides way to bind HTML select element with angularjs model

select directive also provide dynamic option value using ng-repeat and ng-options

When the item from select element is get selected from option then it is bind with the value of ng-model associated with select element using angularjs two way binding.

Setting option value using value attribute of option element will set this value as string.

On selection this value in ng-model the model variable must be string type.

https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.8/angular.min.js

select is

description of parameters fields are self explanatory.

To access value in model you have to provide modal name rest attributes are optional as per requirement any one can use.

let us see one basic example for selecting a value in model

Example

populating select with dynamic values

selecting a id based on value from json array as below

To select multiple in above program use multiple with select element as below

by holding control key with click can select multiple values

Using ng-option with select to generate dynamic option value

pre populating any specific value in ng-options is easy in following example you can see this.

Consider we have to populate Blue as default value then set $scope.favouriteColor=3 in controller

see below

Please follow and like us:
error