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

Commit 0722ab0

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 ee8e05c commit 0722ab0

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
@@ -381,6 +381,12 @@ var ngClassDirective = classDirective('', true);
381381
* This directive can be applied only within the scope of an
382382
* {@link ng.directive:ngRepeat ngRepeat}.
383383
*
384+
* @animations
385+
* | Animation | Occurs |
386+
* |----------------------------------|-------------------------------------|
387+
* | {@link ng.$animate#addClass addClass} | just before the class is applied to the element |
388+
* | {@link ng.$animate#removeClass removeClass} | just before the class is removed from the element |
389+
*
384390
* @element ANY
385391
* @param {expression} ngClassOdd {@link guide/expression Expression} to eval. The result
386392
* of the evaluation can be a string representing space delimited class names or an array.
@@ -413,6 +419,62 @@ var ngClassDirective = classDirective('', true);
413419
});
414420
</file>
415421
</example>
422+
*
423+
* <hr />
424+
* @example
425+
* An example on how to implement animations using `ngClassOdd`:
426+
*
427+
<example module="ngAnimate" deps="angular-animate.js" animations="true" name="ng-class-odd-animate">
428+
<file name="index.html">
429+
<div ng-init="items=['Item 3', 'Item 2', 'Item 1', 'Item 0']">
430+
<button ng-click="items.unshift('Item ' + items.length)">Add item</button>
431+
<hr />
432+
<table>
433+
<tr ng-repeat="item in items" ng-class-odd="'odd'">
434+
<td>{{ item }}</td>
435+
</tr>
436+
</table>
437+
</div>
438+
</file>
439+
<file name="style.css">
440+
.odd {
441+
background: rgba(255, 255, 0, 0.25);
442+
}
443+
444+
.odd-add, .odd-remove {
445+
transition: 1.5s;
446+
}
447+
</file>
448+
<file name="protractor.js" type="protractor">
449+
it('should add new entries to the beginning of the list', function() {
450+
var button = element(by.buttonText('Add item'));
451+
var rows = element.all(by.repeater('item in items'));
452+
453+
expect(rows.count()).toBe(4);
454+
expect(rows.get(0).getText()).toBe('Item 3');
455+
expect(rows.get(1).getText()).toBe('Item 2');
456+
457+
button.click();
458+
459+
expect(rows.count()).toBe(5);
460+
expect(rows.get(0).getText()).toBe('Item 4');
461+
expect(rows.get(1).getText()).toBe('Item 3');
462+
});
463+
464+
it('should add odd class to odd entries', function() {
465+
var button = element(by.buttonText('Add item'));
466+
var rows = element.all(by.repeater('item in items'));
467+
468+
expect(rows.get(0).getAttribute('class')).toMatch(/odd/);
469+
expect(rows.get(1).getAttribute('class')).not.toMatch(/odd/);
470+
471+
button.click();
472+
473+
expect(rows.get(0).getAttribute('class')).toMatch(/odd/);
474+
expect(rows.get(1).getAttribute('class')).not.toMatch(/odd/);
475+
});
476+
</file>
477+
</example>
416478
*/
417479
var ngClassOddDirective = classDirective('Odd', 0);
418480

@@ -429,6 +491,12 @@ var ngClassOddDirective = classDirective('Odd', 0);
429491
* This directive can be applied only within the scope of an
430492
* {@link ng.directive:ngRepeat ngRepeat}.
431493
*
494+
* @animations
495+
* | Animation | Occurs |
496+
* |----------------------------------|-------------------------------------|
497+
* | {@link ng.$animate#addClass addClass} | just before the class is applied to the element |
498+
* | {@link ng.$animate#removeClass removeClass} | just before the class is removed from the element |
499+
*
432500
* @element ANY
433501
* @param {expression} ngClassEven {@link guide/expression Expression} to eval. The
434502
* result of the evaluation can be a string representing space delimited class names or an array.
@@ -461,5 +529,61 @@ var ngClassOddDirective = classDirective('Odd', 0);
461529
});
462530
</file>
463531
</example>
532+
*
533+
* <hr />
534+
* @example
535+
* An example on how to implement animations using `ngClassEven`:
536+
*
537+
<example module="ngAnimate" deps="angular-animate.js" animations="true" name="ng-class-even-animate">
538+
<file name="index.html">
539+
<div ng-init="items=['Item 3', 'Item 2', 'Item 1', 'Item 0']">
540+
<button ng-click="items.unshift('Item ' + items.length)">Add item</button>
541+
<hr />
542+
<table>
543+
<tr ng-repeat="item in items" ng-class-even="'even'">
544+
<td>{{ item }}</td>
545+
</tr>
546+
</table>
547+
</div>
548+
</file>
549+
<file name="style.css">
550+
.even {
551+
background: rgba(255, 255, 0, 0.25);
552+
}
553+
554+
.even-add, .even-remove {
555+
transition: 1.5s;
556+
}
557+
</file>
558+
<file name="protractor.js" type="protractor">
559+
it('should add new entries to the beginning of the list', function() {
560+
var button = element(by.buttonText('Add item'));
561+
var rows = element.all(by.repeater('item in items'));
562+
563+
expect(rows.count()).toBe(4);
564+
expect(rows.get(0).getText()).toBe('Item 3');
565+
expect(rows.get(1).getText()).toBe('Item 2');
566+
567+
button.click();
568+
569+
expect(rows.count()).toBe(5);
570+
expect(rows.get(0).getText()).toBe('Item 4');
571+
expect(rows.get(1).getText()).toBe('Item 3');
572+
});
573+
574+
it('should add even class to even entries', function() {
575+
var button = element(by.buttonText('Add item'));
576+
var rows = element.all(by.repeater('item in items'));
577+
578+
expect(rows.get(0).getAttribute('class')).not.toMatch(/even/);
579+
expect(rows.get(1).getAttribute('class')).toMatch(/even/);
580+
581+
button.click();
582+
583+
expect(rows.get(0).getAttribute('class')).not.toMatch(/even/);
584+
expect(rows.get(1).getAttribute('class')).toMatch(/even/);
585+
});
586+
</file>
587+
</example>
464588
*/
465589
var ngClassEvenDirective = classDirective('Even', 1);

0 commit comments

Comments
 (0)