animation - Animate only new components -


i experimenting new animation api in angular 2, , have following challenge:

i have parent component displays set of child components using *ngfor. ngfor references simple data array in parent component.

requirements:

  1. when parent component rendered initial children, parent , children should rendered instantly (without animation)

  2. when new child components added (because of new object appended data array), new child should animated (e.g. bounce in left).

how can configure animation handle this?

the basic question is: how can child component know if rendered part of initialization of parent or later?

some possible solutions: - can set boolean variable directly on data object says new object created after view , should animated. property checked component. however, don't want introduce kind of view logic in data model. - can use lifecycle hooks in parent component set property in parent says parent rendered , subsequent (new) children should animated. however, haven't been able seems lifecycle hooks executed before children components instantiated.

other solutions?

br anders

  1. you can use property in parent
initialload = true;  ngafterviewinit() {   this.initialload = false; } 

  1. https://github.com/angular/angular/issues/7239#issuecomment-227369239 contains example (with plunker):

@component({   selector: 'app',   template: `   <button (click)="items.push(items.length)">add</button>   <ul>       <template ngfor let-item [ngforof]="items" let-i="index">           <li style="display: block;" @flyinout="'in'" (click)="onclick(i)" *ngif="!!item">{{ }} - {{ item }}</li>       </template>   </ul>   `,   animations: [         trigger('flyinout', [             state('in', style({ opacity: 1, transform: 'translatex(0) scaley(1)' })),             transition('void => *', [                 style({                     opacity: 0,                     transform: 'translatex(-100%)'                 }),                 animate('1s ease-in')             ]),             transition('* => void', [                 animate('1s 10 ease-out', style({                     opacity: .5,                     transform: 'scaley(0.8)'                 }))             ])         ])     ] })  export class app {   private items = [];   constructor() { }    onclick(index) {     //this.items.splice(index,1);     delete this.items[index];   } } 

there issue *ngfor fixed in https://github.com/angular/angular/pull/10287 fix has yet land.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -