title: Call a function every time a page is visited - Ionic 2
body: <p>I am new to Ionic 2 and implementing a small app where I want to call a REST API function whenever I revisit a page. Following a small piece of code that I have implemented.</p>
  
  <pre><code>import { Component } from '@angular/core';
  import { NavController, NavParams, ViewController } from 'ionic-angular';
  import { ItemService } from '../../providers/item-service';
  import { ItemDetailsCartPage } from '../item-details-cart/item-details-cart'
  
  @Component({
    selector: 'page-cart',
    templateUrl: 'cart.html',
    providers: [ItemService]
  })
  export class CartPage {
  
    email;
    sessionId;
    public cartData: any;
    public message: any = [];
  
    constructor(public navCtrl: NavController, 
        public navParams: NavParams, 
        public itemSrvc: ItemService,
        public viewCtrl: ViewController) {}
  
    ionViewDidLoad() {
      this.email = this.navParams.get('email');
      this.sessionId = this.navParams.get('sessionId');;
      this.loadCart();
    }
  
  
    loadCart() {
      this.itemSrvc.getCart(this.email, this.sessionId).then(successData =&gt; {
        this.cartData = successData;
        this.message = this.cartData.message;
      },failureData =&gt; {
        this.cartData = failureData;
        this.message = [{'itemName':'No items in cart', 'quantity': '', 'imgUrl':''}];
      });
    }
  </code></pre>
  
  <p>I have created a cart page which displays the items added in cart by calling an API. The first time I visit the cart page, the API is called and response is received. But second time when I visit the same page again, the same API function is not called.</p>
  
  <p>There might me be some duplicate question regarding this topic but I did not find any relevant answers, after lot of searching on net I have posted this question.</p>