ng-pluralize,添加引导类

时间:2014-05-21 14:51:30

标签: angularjs twitter-bootstrap angularjs-directive

在我的代码中,根据结果,我正在使用

显示消息
<span ng-if="data.length >= 1" class="badge badge-success">{{data.length}}</span>
<span ng-if="data.length == 0" class="badge badge-error">{{data.length}}</span>

2怀疑:

第一:

 <ng-pluralize count="data.length" offset=2
        when="{'0'    : 'No driver. :-(',
        '1'  : ' driver !',
        '2'  : ' {{data[0].Driver.givenName}}, {{data[1].Driver.givenName}} driver !',
        'other': ' {{data[0].Driver.givenName}}, {{data[1].Driver.givenName}} and {} others.'}">
    </ng-pluralize>

以上代码显示:

发现:13塞巴斯蒂安,费尔南多和其他11人。

enter image description here

我知道第一个绿色椭圆来自<span />标签,上面有“徽章徽章成功”,

如果我想将另一个整数值(11)着色为

,该怎么办?
<span class="badge badge-warning">11</span>

我的意思是我应该得到如下结果:

enter image description here

第二:

<!--span ng-class="{ 'badge badge-success' : data.length > 1, badge badge-error }"> {{data.length}}</span--> //Why this is not working ?
Anyways, This I have achieved by using `ng-if` by using 2 span tags, but just for my understanding what is wrong in this span tag conditioning.

1 个答案:

答案 0 :(得分:0)

我选择了一个替代解决方案,使用ng-switch

<div ng-switch="data.length">
                        <div ng-switch-when="0">No drivers. :-(</div>
                        <div ng-switch-when="1">1 driver!</div>
                        <div ng-switch-when="2">{{data[0].Driver.givenName}} and {{data[1].Driver.givenName}} driver !</div>
                        <div ng-switch-default>{{data[0].Driver.givenName}}, {{data[1].Driver.givenName}} and
                            <span class="badge badge-info">{{data.length - 2}}</span> other !</div>
                    </div>,

现在,除了

之外,它还有罚款