我有一个带有[1,2,3]的$ scope.forumList,我想从2开始使用ng-option,我该怎么办?
<select name="forum"
ng-change="filterBlob()"
ng-model='f'
ng-options='f as f.name for f in forumList'
required>
</select>
答案 0 :(得分:2)
只需从js:
切片数组// In your javascript
var newForumList = scope.forumList.slice(1, scope.forumList.length);
然后在这里使用newForumList
<select name="forum"
ng-change="filterBlob()"
ng-model='f'
ng-options='f as f.name for f in newForumList'
required>
</select>
答案 1 :(得分:1)
我不确定您如何处理ng-options
,但使用option
,可以使用ng-if
在此demo中执行此操作。
请找到以下代码:
HTML:
<div ng-app="app" ng-controller="test">
<select ng-model="selected">
<option value="">Select</option>
<option ng-repeat="item in data" ng-value="item" ng-if="$index > 0">{{item}}
</option>
</div>
JS:
var app = angular. module('app',[]);
app.controller ('test', function ($scope){
$scope.data = [1,2,3,4];
});
答案 2 :(得分:-1)
您需要使用splice()
代替slice
例如:
var a = [1,2,3,4]
var b = a.splice(1, a.length)
返回[2,3,4]