Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ngAfterContentInit in ListView template component #883

Closed
Serge-SDL opened this issue Jul 6, 2017 · 2 comments
Closed

ngAfterContentInit in ListView template component #883

Serge-SDL opened this issue Jul 6, 2017 · 2 comments
Labels

Comments

@Serge-SDL
Copy link

Hi!
I found a strange behavior with ListView I can't understand it...
If I have created a very basic list:

  template: `
    <ListView [items]="rows" (itemTap)="onItemTap($event)">
      <ng-template let-item="item" let-i="index">
        <list-with-picture-template-cmp [document]="item"></list-with-picture-template-cmp>
      </ng-template>
    </ListView>
  `,

With a simple component as template:

import { Component, Input, AfterContentInit } from '@angular/core';

@Component({
  selector: "list-with-picture-template-cmp",

  template: `
  <GridLayout style="background-color: white" columns="auto, *">
      <Label text="{{ document.designation }}"></Label>
  </GridLayout>
  `
})
export class ListWithPictureTemplateComponent implements AfterContentInit {

  @Input() document: any;

  ngAfterContentInit() {
    console.log('ListWithPictureTemplateComponent - ngAfterContentInit');
  }
}

When I log ngAfterContentInit, I see that the function is called only for the initialy displayed elements. When I move the mouse to reach other elements, the ngAfterContentInit is called on more time for the first next element but that’s it, no more call no matter how long is the list. It’s a problem because I need to execute some code for each element in the list.

I think it's bug or I don't understand this behavior...

@Buuhuu
Copy link
Contributor

Buuhuu commented Jul 10, 2017

This is due to the view recycling done by the native views. You can use ngOnChanges() callback if you want to get notified about views data binding has been changed. (Change detection is triggered by the list view component on the views created from the template(s)).

@Serge-SDL
Copy link
Author

Thnak you very much, works for me !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants