以下是plunker链接:http://plnkr.co/edit/LqeGqg1HdOIkiMQrKn72?p=preview
HTML:
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.0.x" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js" data-semver="1.0.7"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<select ng-model="animalSelection"
ng-options="a.name group by a.subcat for a in animals">
</select>
</body>
</html>
JS:
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
var animals = [
{name: "great dane", subcat: "Dogs"},
{name: "lab", subcat: "Dogs"},
{name: "tabby", subcat: "Cats"},
{name: "black", subcat: "Cats"}
];
// and put it in the $scope
$scope.animals = animals;
});
我想根据示例
选择子猫,即Dogs Cats