AngularJS处理ng-options首项空白代码
html代码:
<body ng-app="myApp" ng-controller="myCtrl">
<div>
选择内容:
<select ng-model="selectedPeople" ng-options="v.name for v in people"></select>
<p>ng-repeat解决首项空白:</p>
<select>
<option ng-repeat="v in people">{{ v.name }}</option>
</select>
<p>ng-options解决首项空白:</p>
<select ng-model="selectedYourPeople" ng-options="v.name as v.name for v in people"></select>
</div>
</body>
JavaScript代码:
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
console.log(9999)
$scope.people = [
{id: 0,name: 'php',},
{id: 1,name: 'JavaScript',},
{id: 2,name: 'Java',},
{id: 3,name: 'c#',}
];
$scope.selectedYourPeople = $scope.people[0].name;
});
</script>