@@ -338,6 +338,12 @@ var ngClassDirective = classDirective('', true);
338
338
* This directive can be applied only within the scope of an
339
339
* {@link ng.directive:ngRepeat ngRepeat}.
340
340
*
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
+ *
341
347
* @element ANY
342
348
* @param {expression } ngClassOdd {@link guide/expression Expression } to eval. The result
343
349
* of the evaluation can be a string representing space delimited class names or an array.
@@ -370,6 +376,62 @@ var ngClassDirective = classDirective('', true);
370
376
});
371
377
</file>
372
378
</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>
373
435
*/
374
436
var ngClassOddDirective = classDirective ( 'Odd' , 0 ) ;
375
437
@@ -386,6 +448,12 @@ var ngClassOddDirective = classDirective('Odd', 0);
386
448
* This directive can be applied only within the scope of an
387
449
* {@link ng.directive:ngRepeat ngRepeat}.
388
450
*
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
+ *
389
457
* @element ANY
390
458
* @param {expression } ngClassEven {@link guide/expression Expression } to eval. The
391
459
* 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);
418
486
});
419
487
</file>
420
488
</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>
421
545
*/
422
546
var ngClassEvenDirective = classDirective ( 'Even' , 1 ) ;
0 commit comments