ng-option从第2位开始

时间:2016-03-20 04:59:36

标签: html angularjs

我有一个带有[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>

3 个答案:

答案 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]