Angular implementing the Ng-options of Select

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.