NG implements a simple Select
<DivNg-controller= "Ngselect"> <SelectNg-model= "Vm.selectval"ng-options= "O.title for O in Vm.optionsdata"> <optionvalue="">Please select</option> </Select></Div>
var app = Angular.module ("app", []); App.controller ("ngselect",function($scope) { var vm = $scope. VM = {}; // The array object is used to traverse the Ng-options Vm.optionsdata = [{ "angularJs" },{ "Emberjs" },{ " Backbonejs " },{ " Knockoutjs " }];})
Value for ng-options Custom option
< select ng-model = "Vm.selectval" Ng-options = "o.id as O.title for O in Vm.optionsdata" Ng-change = "Selectchange ()" > < option value = "" > Please select </ option > </ select >
The id attribute was added as the value of option
You may see in Page view that option generates value 0,1,2,3 because angular automatically adds values indexed as value
Let's take a look at the Ng-change event Monitor.
Vm.optionsdata = [{ 4543, "AngularJs"},{ 546, "Emberjs"} , { 456, "backbonejs "},{ , "Knockoutjs" function () { // added Ng-change event to try output console.log (vm.selectval) of ID value;}
Online Demo
Angular implementing the Ng-options of Select