AngularJS UI 引导程序“btn-radio"指令不起作用 [英] AngularJS UI Bootstrap "btn-radio" directive doesn't work

查看:25
本文介绍了AngularJS UI 引导程序“btn-radio"指令不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现场演示

谁能解释为什么前两个按钮组起作用,而第三个不起作用?

<button ng-repeat="公司中的公司"类=btn"ng-model="radioModel.id"btn-radio="company.id">{{公司名}}

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

<div class="btn-group"><button ng-repeat="公司中的公司"class="btn btn-{{ company.name }}"ng-model="radioModel.id"btn-radio="company.id">{{公司名}}

$scope.companies = [ { id: 2, name: "two"}, {id: 3, name: "three"} ];$scope.radioModel = { id: 3 };

此示例使用 AngularUI Bootstrap 0.5.0.如果我将其更改为 0.3.0,一切都会按预期进行.

解决方案

使用 ng-class.class 中的字符串插值很时髦.

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

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.

解决方案

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

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

这篇关于AngularJS UI 引导程序“btn-radio"指令不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆