Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 02f4ca4

Browse files
frederikprijckgkalpak
authored andcommitted
docs(ngClass): add docs regarding animation for ngClassEven and ngClassOdd
Previously, the documentation has no information regarding using `ngAnimate` together with the `ngClassEven` and `ngClassOdd` directives. This commit adds the same docs used by the `ngClass` directive to the `ngClassEven` and `ngClassOdd` docs and adds an extra example for both `ngClassEven` and `ngClassOdd` that showcases animations. Closes #15654
1 parent 8d6ac5f commit 02f4ca4

File tree

2 files changed

+128
-3
lines changed

2 files changed

+128
-3
lines changed

docs/content/guide/animations.ngdoc

+4-3
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,12 @@ triggered:
229229
| {@link ngRoute.directive:ngView#animations ngView} | enter and leave |
230230
| {@link module:ngMessages#animations ngMessage / ngMessageExp} | enter and leave |
231231
| {@link ng.directive:ngClass#animations ngClass / {{class}​}} | add and remove |
232-
| {@link ng.directive:ngClass#animations ngClassEven / ngClassOdd} | add and remove |
232+
| {@link ng.directive:ngClassEven#animations ngClassEven} | add and remove |
233+
| {@link ng.directive:ngClassOdd#animations ngClassOdd} | add and remove |
233234
| {@link ng.directive:ngHide#animations ngHide} | add and remove (the `ng-hide` class) |
234235
| {@link ng.directive:ngShow#animations ngShow} | add and remove (the `ng-hide` class) |
235-
| {@link ng.directive:ngModel#animations ngModel} | add and remove ({@link ng.directive:ngModel#css-classes various classes}) |
236-
| {@link ng.directive:form#animations form / ngForm} | add and remove ({@link ng.directive:form#css-classes various classes}) |
236+
| {@link ng.directive:ngModel#animations ngModel} | add and remove ({@link ng.directive:ngModel#css-classes various classes}) |
237+
| {@link ng.directive:form#animations form / ngForm} | add and remove ({@link ng.directive:form#css-classes various classes}) |
237238
| {@link module:ngMessages#animations ngMessages} | add and remove (the `ng-active`/`ng-inactive` classes) |
238239

239240
For a full breakdown of the steps involved during each animation event, refer to the

src/ng/directive/ngClass.js

+124
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,12 @@ var ngClassDirective = classDirective('', true);
338338
* This directive can be applied only within the scope of an
339339
* {@link ng.directive:ngRepeat ngRepeat}.
340340
*
341+
* @animations
342+
* | Animation | Occurs |
343+
* |----------------------------------|-------------------------------------|
344+
* | {@link ng.$animate#addClass addClass} | just before the class is applied to the element |
345+
* | {@link ng.$animate#removeClass removeClass} | just before the class is removed from the element |
346+
*
341347
* @element ANY
342348
* @param {expression} ngClassOdd {@link guide/expression Expression} to eval. The result
343349
* of the evaluation can be a string representing space delimited class names or an array.
@@ -370,6 +376,62 @@ var ngClassDirective = classDirective('', true);
370376
});
371377
</file>
372378
</example>
379+
*
380+
* <hr />
381+
* @example
382+
* An example on how to implement animations using `ngClassOdd`:
383+
*
384+
<example module="ngAnimate" deps="angular-animate.js" animations="true" name="ng-class-odd-animate">
385+
<file name="index.html">
386+
<div ng-init="items=['Item 3', 'Item 2', 'Item 1', 'Item 0']">
387+
<button ng-click="items.unshift('Item ' + items.length)">Add item</button>
388+
<hr />
389+
<table>
390+
<tr ng-repeat="item in items" ng-class-odd="'odd'">
391+
<td>{{ item }}</td>
392+
</tr>
393+
</table>
394+
</div>
395+
</file>
396+
<file name="style.css">
397+
.odd {
398+
background: rgba(255, 255, 0, 0.25);
399+
}
400+
401+
.odd-add, .odd-remove {
402+
transition: 1.5s;
403+
}
404+
</file>
405+
<file name="protractor.js" type="protractor">
406+
it('should add new entries to the beginning of the list', function() {
407+
var button = element(by.buttonText('Add item'));
408+
var rows = element.all(by.repeater('item in items'));
409+
410+
expect(rows.count()).toBe(4);
411+
expect(rows.get(0).getText()).toBe('Item 3');
412+
expect(rows.get(1).getText()).toBe('Item 2');
413+
414+
button.click();
415+
416+
expect(rows.count()).toBe(5);
417+
expect(rows.get(0).getText()).toBe('Item 4');
418+
expect(rows.get(1).getText()).toBe('Item 3');
419+
});
420+
421+
it('should add odd class to odd entries', function() {
422+
var button = element(by.buttonText('Add item'));
423+
var rows = element.all(by.repeater('item in items'));
424+
425+
expect(rows.get(0).getAttribute('class')).toMatch(/odd/);
426+
expect(rows.get(1).getAttribute('class')).not.toMatch(/odd/);
427+
428+
button.click();
429+
430+
expect(rows.get(0).getAttribute('class')).toMatch(/odd/);
431+
expect(rows.get(1).getAttribute('class')).not.toMatch(/odd/);
432+
});
433+
</file>
434+
</example>
373435
*/
374436
var ngClassOddDirective = classDirective('Odd', 0);
375437

@@ -386,6 +448,12 @@ var ngClassOddDirective = classDirective('Odd', 0);
386448
* This directive can be applied only within the scope of an
387449
* {@link ng.directive:ngRepeat ngRepeat}.
388450
*
451+
* @animations
452+
* | Animation | Occurs |
453+
* |----------------------------------|-------------------------------------|
454+
* | {@link ng.$animate#addClass addClass} | just before the class is applied to the element |
455+
* | {@link ng.$animate#removeClass removeClass} | just before the class is removed from the element |
456+
*
389457
* @element ANY
390458
* @param {expression} ngClassEven {@link guide/expression Expression} to eval. The
391459
* result of the evaluation can be a string representing space delimited class names or an array.
@@ -418,5 +486,61 @@ var ngClassOddDirective = classDirective('Odd', 0);
418486
});
419487
</file>
420488
</example>
489+
*
490+
* <hr />
491+
* @example
492+
* An example on how to implement animations using `ngClassEven`:
493+
*
494+
<example module="ngAnimate" deps="angular-animate.js" animations="true" name="ng-class-even-animate">
495+
<file name="index.html">
496+
<div ng-init="items=['Item 3', 'Item 2', 'Item 1', 'Item 0']">
497+
<button ng-click="items.unshift('Item ' + items.length)">Add item</button>
498+
<hr />
499+
<table>
500+
<tr ng-repeat="item in items" ng-class-even="'even'">
501+
<td>{{ item }}</td>
502+
</tr>
503+
</table>
504+
</div>
505+
</file>
506+
<file name="style.css">
507+
.even {
508+
background: rgba(255, 255, 0, 0.25);
509+
}
510+
511+
.even-add, .even-remove {
512+
transition: 1.5s;
513+
}
514+
</file>
515+
<file name="protractor.js" type="protractor">
516+
it('should add new entries to the beginning of the list', function() {
517+
var button = element(by.buttonText('Add item'));
518+
var rows = element.all(by.repeater('item in items'));
519+
520+
expect(rows.count()).toBe(4);
521+
expect(rows.get(0).getText()).toBe('Item 3');
522+
expect(rows.get(1).getText()).toBe('Item 2');
523+
524+
button.click();
525+
526+
expect(rows.count()).toBe(5);
527+
expect(rows.get(0).getText()).toBe('Item 4');
528+
expect(rows.get(1).getText()).toBe('Item 3');
529+
});
530+
531+
it('should add even class to even entries', function() {
532+
var button = element(by.buttonText('Add item'));
533+
var rows = element.all(by.repeater('item in items'));
534+
535+
expect(rows.get(0).getAttribute('class')).not.toMatch(/even/);
536+
expect(rows.get(1).getAttribute('class')).toMatch(/even/);
537+
538+
button.click();
539+
540+
expect(rows.get(0).getAttribute('class')).not.toMatch(/even/);
541+
expect(rows.get(1).getAttribute('class')).toMatch(/even/);
542+
});
543+
</file>
544+
</example>
421545
*/
422546
var ngClassEvenDirective = classDirective('Even', 1);

0 commit comments

Comments
 (0)