AngularJS UI Bootstrap “btn-radio” directive doesn

2019-08-28 03:30发布

问题:

Live Demo

Could anyone explain why the first two button groups work, but the third one doesn't?

<div class="btn-group">
  <button ng-repeat="company in companies" 
          class="btn" 
          ng-model="radioModel.id" 
          btn-radio="company.id">
    {{company.name}}
  </button>
</div>

<div class="btn-group">
  <button class="btn btn-two" 
          ng-model="radioModel.id"
          btn-radio="2">
    two
  </button>
  <button class="btn btn-two" 
          ng-model="radioModel.id"
          btn-radio="3">
    three
  </button>
</div>

<div class="btn-group">
  <button ng-repeat="company in companies" 
          class="btn btn-{{ company.name }}" 
          ng-model="radioModel.id" 
          btn-radio="company.id">
    {{company.name}}
  </button>
</div>
$scope.companies = [ { id: 2, name: "two"}, {id: 3, name: "three"} ];
$scope.radioModel = { id: 3 };

This example uses AngularUI Bootstrap 0.5.0. If I change it to 0.3.0, everything works as expected.

回答1:

Use ng-class. The string interpolation in class is funky.

ng-class="'btn btn-' + company.name"