1

我想在 angularJS 中做这样的事情:

<div ng-class="{ 'hover-accordion': angular.element(this).children().length >= 3 }">
    <div ng-if="showA">...</div>
    <div ng-if="showB">...</div>
    <div ng-if="showC">...</div>
    <div ng-if="showD">...</div>
    <div ng-if="showE">...</div>
</div>

这意味着如果父 div 有超过 3 个孩子,我想要类“悬停手风琴”。
可能吗?

4

2 回答 2

2

Mostly templates display a model (data from server). Use this model to alter the view. I wouldn't rely on the underlying DOM to manipulate the view. Sure you can but this wouldn't be the angular way. So instead of checking the length of children of a dom element, check the length of the model data that is rendered by the view.

Here is a working plunker of what I mean: http://plnkr.co/edit/SzuAO1BTapelQYI6WFJa?p=preview

于 2013-11-07T10:38:31.670 回答
-1

孩子是由PHP(或其他服务器端代码)制作的吗?用 PHP 计算并添加类。但是如果孩子是用角模型制作的,就使用模型的长度。

正确的 ?

于 2013-11-07T10:12:35.120 回答