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

docs(ngClass): Add docs for ngClassOdd and ngClassEven regarding anim… #15654

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions docs/content/guide/animations.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,12 @@ triggered:
| {@link ngRoute.directive:ngView#animations ngView} | enter and leave |
| {@link module:ngMessages#animations ngMessage / ngMessageExp} | enter and leave |
| {@link ng.directive:ngClass#animations ngClass / {{class}​}} | add and remove |
| {@link ng.directive:ngClass#animations ngClassEven / ngClassOdd} | add and remove |
| {@link ng.directive:ngClassEven#animations ngClassEven} | add and remove |
| {@link ng.directive:ngClassOdd#animations ngClassOdd} | add and remove |
| {@link ng.directive:ngHide#animations ngHide} | add and remove (the `ng-hide` class) |
| {@link ng.directive:ngShow#animations ngShow} | add and remove (the `ng-hide` class) |
| {@link ng.directive:ngModel#animations ngModel} | add and remove ({@link ng.directive:ngModel#css-classes various classes}) |
| {@link ng.directive:form#animations form / ngForm} | add and remove ({@link ng.directive:form#css-classes various classes}) |
| {@link ng.directive:ngModel#animations ngModel} | add and remove ({@link ng.directive:ngModel#css-classes various classes}) |
| {@link ng.directive:form#animations form / ngForm} | add and remove ({@link ng.directive:form#css-classes various classes}) |
| {@link module:ngMessages#animations ngMessages} | add and remove (the `ng-active`/`ng-inactive` classes) |

For a full breakdown of the steps involved during each animation event, refer to the
Expand Down
124 changes: 124 additions & 0 deletions src/ng/directive/ngClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,12 @@ var ngClassDirective = classDirective('', true);
* This directive can be applied only within the scope of an
* {@link ng.directive:ngRepeat ngRepeat}.
*
* @animations
* | Animation | Occurs |
* |----------------------------------|-------------------------------------|
* | {@link ng.$animate#addClass addClass} | just before the class is applied to the element |
* | {@link ng.$animate#removeClass removeClass} | just before the class is removed from the element |
*
* @element ANY
* @param {expression} ngClassOdd {@link guide/expression Expression} to eval. The result
* of the evaluation can be a string representing space delimited class names or an array.
Expand Down Expand Up @@ -370,6 +376,62 @@ var ngClassDirective = classDirective('', true);
});
</file>
</example>
*
* <hr />
* @example
* An example on how to implement animations using `ngClassOdd`:
*
<example module="ngAnimate" deps="angular-animate.js" animations="true" name="ng-class-odd-animate">
<file name="index.html">
<div ng-init="items=['Item 3', 'Item 2', 'Item 1', 'Item 0']">
<button ng-click="items.unshift('Item ' + items.length)">Add item</button>
<hr />
<table>
<tr ng-repeat="item in items" ng-class-odd="'odd'">
<td>{{ item }}</td>
</tr>
</table>
</div>
</file>
<file name="style.css">
.odd {
background: rgba(255, 255, 0, 0.25);
}

.odd-add, .odd-remove {
transition: 1.5s;
}
</file>
<file name="protractor.js" type="protractor">
it('should add new entries to the beginning of the list', function() {
var button = element(by.buttonText('Add item'));
var rows = element.all(by.repeater('item in items'));

expect(rows.count()).toBe(4);
expect(rows.get(0).getText()).toBe('Item 3');
expect(rows.get(1).getText()).toBe('Item 2');

button.click();

expect(rows.count()).toBe(5);
expect(rows.get(0).getText()).toBe('Item 4');
expect(rows.get(1).getText()).toBe('Item 3');
});

it('should add odd class to odd entries', function() {
var button = element(by.buttonText('Add item'));
var rows = element.all(by.repeater('item in items'));

expect(rows.get(0).getAttribute('class')).toMatch(/odd/);
expect(rows.get(1).getAttribute('class')).not.toMatch(/odd/);

button.click();

expect(rows.get(0).getAttribute('class')).toMatch(/odd/);
expect(rows.get(1).getAttribute('class')).not.toMatch(/odd/);
});
</file>
</example>
*/
var ngClassOddDirective = classDirective('Odd', 0);

Expand All @@ -386,6 +448,12 @@ var ngClassOddDirective = classDirective('Odd', 0);
* This directive can be applied only within the scope of an
* {@link ng.directive:ngRepeat ngRepeat}.
*
* @animations
* | Animation | Occurs |
* |----------------------------------|-------------------------------------|
* | {@link ng.$animate#addClass addClass} | just before the class is applied to the element |
* | {@link ng.$animate#removeClass removeClass} | just before the class is removed from the element |
*
* @element ANY
* @param {expression} ngClassEven {@link guide/expression Expression} to eval. The
* result of the evaluation can be a string representing space delimited class names or an array.
Expand Down Expand Up @@ -418,5 +486,61 @@ var ngClassOddDirective = classDirective('Odd', 0);
});
</file>
</example>
*
* <hr />
* @example
* An example on how to implement animations using `ngClassEven`:
*
<example module="ngAnimate" deps="angular-animate.js" animations="true" name="ng-class-even-animate">
<file name="index.html">
<div ng-init="items=['Item 3', 'Item 2', 'Item 1', 'Item 0']">
<button ng-click="items.unshift('Item ' + items.length)">Add item</button>
<hr />
<table>
<tr ng-repeat="item in items" ng-class-even="'even'">
<td>{{ item }}</td>
</tr>
</table>
</div>
</file>
<file name="style.css">
.even {
background: rgba(255, 255, 0, 0.25);
}

.even-add, .even-remove {
transition: 1.5s;
}
</file>
<file name="protractor.js" type="protractor">
it('should add new entries to the beginning of the list', function() {
var button = element(by.buttonText('Add item'));
var rows = element.all(by.repeater('item in items'));

expect(rows.count()).toBe(4);
expect(rows.get(0).getText()).toBe('Item 3');
expect(rows.get(1).getText()).toBe('Item 2');

button.click();

expect(rows.count()).toBe(5);
expect(rows.get(0).getText()).toBe('Item 4');
expect(rows.get(1).getText()).toBe('Item 3');
});

it('should add even class to even entries', function() {
var button = element(by.buttonText('Add item'));
var rows = element.all(by.repeater('item in items'));

expect(rows.get(0).getAttribute('class')).not.toMatch(/even/);
expect(rows.get(1).getAttribute('class')).toMatch(/even/);

button.click();

expect(rows.get(0).getAttribute('class')).not.toMatch(/even/);
expect(rows.get(1).getAttribute('class')).toMatch(/even/);
});
</file>
</example>
*/
var ngClassEvenDirective = classDirective('Even', 1);