AngularJS UI Bootstrap “btn-radio” directive doesn't work

一笑奈何 提交于 2019-12-13 04:32:29

问题


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" 


来源:https://stackoverflow.com/questions/18275727/angularjs-ui-bootstrap-btn-radio-directive-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!