The best practise of the ng-options of Angularjs

Source: Internet
Author: User

Nonsense not much to say, directly on the code.

function Myselectctrl ($scope) {  $scope. Model = [    {      id:10002,      maincategory: ' Male ',      ProductName: ' Washed T-shirt ',      productcolor: ' Black '    },    {      id:10004,      Maincategory: ' Female ',      ProductName: ' V-neck short sleeves ',      productcolor: ' Red '    },    {      id:10006,      Maincategory: ' Male ',      ProductName: ' Round neck long sleeves ',      productcolor: ' White '    }];    $scope. Selected = 10002;}

  

<select ng-model= "selected" Ng-options= "M.id as (M.productcolor + '-' + m.productname) for M in model" >  <o Ption value= "" >--Choose a try--</option></select>
    • It is recommended not to pass resource directly to the API, as long as the string or integer (such as binding is Ng-model= "selected")
    • Do not control angular generated by the <option>...</option> value is what, want to pass what values to the back end in Ng-options= "" in the first parameter to write, as this example is M.id

Write down these, I hope I will not be angular the default check and the value of the problem interference!

The best practise of the ng-options of Angularjs

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.