2014-07-07 112 views
2

似乎有轉換ui.bootstrap.buttons與NG-重複使用的問題。該ui.bootstrap.buttons例子和文檔是在這裏:http://angular-ui.github.io/bootstrap/ui.bootstrap.buttons與NG-重複

Bascially默認的例子很好地工作:http://plnkr.co/edit/2O81y57GtfP6EPNH9qYa?p=preview

<div class="btn-group"> 
    <label class="btn btn-primary" ng-model="radioModel" btn-radio="'Left'">Left</label> 
    <label class="btn btn-primary" ng-model="radioModel" btn-radio="'Middle'">Middle</label> 
    <label class="btn btn-primary" ng-model="radioModel" btn-radio="'Right'">Right</label> 
</div> 

但是,當它轉化利用NG重複,它打破:http://plnkr.co/edit/nzx1VTGN4Q59JlFCU53V?p=preview

<div class="btn-group"> 
    <label ng-repeat="test in ['Left', 'Middle', 'Right']" class="btn btn-primary" ng-model="radioModel" btn-radio="'{{test}}'">{{test}}</label> 
</div> 

回答

7

嘗試

<label ng-repeat="test in ['Left', 'Middle', 'Right']" btn-radio="test" class="btn btn-primary" ng-model="radio.model"> 

代替

btn-radio="'{{test}}'"

在此ng-repeat的頂部,所以你需要考慮這個問題,以及正在創造一個新的範圍。這是一個工作普拉克:http://plnkr.co/edit/h5e5OgFCqv28MPy4tEaM?p=preview

+0

繁瑣,它工作在你普拉克。 'UIB鍵式radio'。在我的plunk中使用ng-repeat時,它不會改變模型的值。 http://plnkr.co/edit/L4gRDqhvuUKDl9NbpIR6?p=preview 我應該採取:'$ parent.model'。 –

1

在某些測試中,我得到它的工作使用納克級的初始選擇的價值和自己的NG-click處理改變選擇的按鈕後,結束

爲按鈕的HTML代碼:

<div class="btn-group"> 
    <button ng-repeat="(timelineIndex, timeline) in timelines" ng-click="selectTimeline(timeline)" ng-class="{active: timeline.name === selectedTimeline.name}" class="btn btn-primary"> 
     {{timeline.name}} 
    </button> 
    </div> 

在控制器:

$scope.selectTimeline = function(activeTimeline) { 
    $scope.selectedTimeline = activeTimeline; 
    };