Javascript 如何使用ng repeat在一次迭代中访问(item in items)的2个项

Javascript 如何使用ng repeat在一次迭代中访问(item in items)的2个项,javascript,angularjs,Javascript,Angularjs,我正在尝试让我的菜单页面必须同时有两个按钮,但我需要使用ng repeat同时生成两个按钮。有人对另一种方法有什么建议,或者有没有办法使用ng repeat来实现这一点 这是我的这个部分视图的html代码 <div> <div ng-repeat="buttons in menuButtons | exactMatchFilter"> <div class="btn-group btn-group-justified">

我正在尝试让我的菜单页面必须同时有两个按钮,但我需要使用ng repeat同时生成两个按钮。有人对另一种方法有什么建议,或者有没有办法使用ng repeat来实现这一点

这是我的这个部分视图的html代码

<div>
    <div ng-repeat="buttons in menuButtons | exactMatchFilter">

        <div class="btn-group btn-group-justified">

        <!--Button 1-->
            <div class="btn-group">
                <button type="button" class="btn btn-default" ng-click="goToView1()">{{buttons[0].info}}</button>
            </div>

           <!--Button 2-->
            <div class="btn-group">
                <button type="button" class="btn btn-default" ng-click="goToView1()">{{buttons[1].info}}</button>
            </div>

        </div>
    </div>
</div>

{{按钮[0].info}
{{按钮[1].info}

我只添加了按钮[1],[0],这样你就可以看到我在做什么我知道你不能在这里添加索引

你可以这样写按钮对象

var buttons = { 
 one: { info: 'someinfo'},
 two: { info: 'someInfo' }
};
<!--Button 1-->
<div class="btn-group">
   <button type="button" class="btn btn-default" ng-click="goToView1()">{{buttons.one.info}}</button>
</div>

<!--Button 2-->
   <div class="btn-group">
      <button type="button" class="btn btn-default" ng-click="goToView1()">{{buttons.two.info}}</button>
   </div>
然后在ng重复你可以像这样

var buttons = { 
 one: { info: 'someinfo'},
 two: { info: 'someInfo' }
};
<!--Button 1-->
<div class="btn-group">
   <button type="button" class="btn btn-default" ng-click="goToView1()">{{buttons.one.info}}</button>
</div>

<!--Button 2-->
   <div class="btn-group">
      <button type="button" class="btn btn-default" ng-click="goToView1()">{{buttons.two.info}}</button>
   </div>

{{buttons.one.info}
{{buttons.two.info}
如果要立即执行此操作,可能需要编写自定义ng指令

  angular.module('docsSimpleDirective', [])
    .controller('Controller', ['$scope', function($scope) {
      $scope.button = {
        one: {info: 'some info'},
        two: {info: 'other info'}
      };
    }])
    .directive('myButtons', function() {
      return {
        template: '<button>{{button.one.info}}</button> <button>{{button.two.info}}</button>'
      };
    });
angular.module('docsSimpleDirective',[])
.controller('controller',['$scope',function($scope){
$scope.button={
一:{info:'some info'},
二:{info:'other info'}
};
}])
.directive('myButtons',function(){
返回{
模板:“{button.one.info}{{button.two.info}”
};
});