Iap2 listing store products issue

Hi there i am using this code for listing my google play products;

in .ts file

constructor(...) {
   this.platform.ready().then(() => {
      this.store.ready(() => {
         this.products = this.store.products;
      });
   });
}

in .html file

		<div class="products_container" *ngFor="let product of products">
			<div class="product_box" (click)="buy(product)">
				<div class="product_box_left">{{product.title}}</div>
				<div class="product_box_right">{{product.price}}</div>
			</div>
		</div>

when i first visit my page in app it works well as below (i made blur somewhere because it’s not english);

then if i visit this page again in my app it adds empty objects in the list;

it repeats every visist this page. If i close the app and start again it returns starting position.

Is there any information about my fault?

best regards

Hi!

Your array is filled every time you enter this screen, to resolve it, set the array to zero before filling.

Load in the constructror, is not the best way…

ionViewDidEnter() is better!

constructor(...) {
this.products = [];  // <<<<<<<<
   this.platform.ready().then(() => {
      this.store.ready(() => {
         this.products = this.store.products;
      });
   });
}

This is solve your problem…

:upside_down_face:

thanks for your response but i faced same issue still :frowning:
i used like this :

  ionViewDidEnter() {
    this.products = [];
    this.platform.ready().then(() => {
      this.store.verbosity = this.store.DEBUG;

      this.registerProducts();
      this.setupListeners();
      
      this.store.ready(() => {
        this.products = this.store.products;
        this.ref.detectChanges();
      });
    });
  }

and also try this code in constructor but same issue i had. Am i wrong about this code i really don’t know

edit: i use this code to add products array also;

products: IAPProduct[] = [];

this can be the problem?