2014-04-23 31 views
0

我想讓我的菜單頁必須並排按鈕,但我需要使用ng-once重複一次有一個建議,以另一種方式或者是有一種用NG-重複如何在一次迭代中使用ng-repeat訪問2項(項目中的項目)

這裏做,這是對這個局部視圖我的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> 

我只加按鈕[1],[0 ]所以你可以看到什麼即時嘗試做我知道你不能在這裏添加索引

回答

0

你可以寫按鈕ob這樣

var buttons = { 
one: { info: 'someinfo'}, 
two: { info: 'someInfo' } 
}; 

然後JECT如果你想一次你可能需要編寫自定義的NG-指令,要做到這一點NG-重複你可以這樣

<!--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> 

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>' 
     }; 
    });