Set the Select default value-angular

Source: Internet
Author: User
Set the Select default value-angular

1.HTML Code

<body ng-app="MyModule">
<div ng-controller="Myctrl">
<select ng-model="MyLabel" ng-options="V.label for V in lists"></select>
</div>
</body>

2.JS Code

var mymodule = angular.module ("MyModule", []);
Mymodule.controller (' Myctrl ', [' $scope ',
function ($scope) {
$scope. Lists = [
{"Label": "Step 1", "Value": "111"},
{"Label": "Step 2", "Value": "233"}
];
$scope. MyLabel = $scope. lists[0];//default array The first value as option
}
]);

3. Implementation results: The default display "Step 1"

4. Extended--ng-options usage [1]

The Ng-optins property can use an array or object in an expression to automatically generate an option list of Select, similar to Ng-repeat.

General usage:

For arrays:

L V.value for V in array

L V.value as V.label for V in array//V.label value as V.value

For objects:

L Label for (key, value) in Object

L Select as label for (key, value) in Object

5. References: More usage reference links

[1].http://www.cnblogs.com/panda-zhang/p/5290694.html

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.