【发布时间】:2014-01-23 21:05:57
【问题描述】:
如何使用 Angular ng-options 在 <select> 选项中添加前导空格?
<div ng-controller="MyCntrl">
Static values (works)
<select>
<option value="black">black</option>
<option value="white"> white</option>
<option value="red"> red</option>
<option value="blue"> blue</option>
<option value="yellow"> yellow</option>
</select>
Values from JS using angular (only the first-default works)
<select ng-model="color" ng-options="c.name for c in colors">
<option value=""> default</option>
</select>
</div>
JS:
angular.module("myApp", []).
controller("MyCntrl", ['$scope', function ($scope) {
$scope.colors = [{
name: 'black',
shade: 'dark'
}, {
name: ' white',
shade: 'light'
}, {
name: ' red',
shade: 'dark'
}, {
name: ' blue',
shade: 'dark'
}, {
name: ' yellow', // spaces here
shade: 'light'
}];
}]);
【问题讨论】:
标签: angularjs