@@ -381,6 +381,12 @@ var ngClassDirective = classDirective('', true);
381
381
* This directive can be applied only within the scope of an
382
382
* {@link ng.directive:ngRepeat ngRepeat}.
383
383
*
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
+ *
384
390
* @element ANY
385
391
* @param {expression } ngClassOdd {@link guide/expression Expression } to eval. The result
386
392
* of the evaluation can be a string representing space delimited class names or an array.
@@ -413,6 +419,62 @@ var ngClassDirective = classDirective('', true);
413
419
});
414
420
</file>
415
421
</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>
416
478
*/
417
479
var ngClassOddDirective = classDirective ( 'Odd' , 0 ) ;
418
480
@@ -429,6 +491,12 @@ var ngClassOddDirective = classDirective('Odd', 0);
429
491
* This directive can be applied only within the scope of an
430
492
* {@link ng.directive:ngRepeat ngRepeat}.
431
493
*
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
+ *
432
500
* @element ANY
433
501
* @param {expression } ngClassEven {@link guide/expression Expression } to eval. The
434
502
* 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);
461
529
});
462
530
</file>
463
531
</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>
464
588
*/
465
589
var ngClassEvenDirective = classDirective ( 'Even' , 1 ) ;
0 commit comments