Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49230

Ionic 4 beta how to fire constructor on navigating to same route?

$
0
0

@ArsalanSavand wrote:

Hi,

I’m using Ionic 4 latest beta version and all my pages and components are lazy loaded.
I have a component called “EntriesComponent” that in its ngOnInit function I get data from an endpoint, and everything works fine.

Problem is, when I’m already in my EntriesComponent view ( route ) and I want to navigate to it again, the component’s ngOnInit function won’t fire also the constructor.

import { Component, OnInit } from '@angular/core';
import Entry from '../../models/entry';
import { AuthService } from '../../services/auth/auth.service';

@Component({
  selector: 'app-entries',
  templateUrl: './entries.component.html',
  styleUrls: ['./entries.component.scss']
})
export class EntriesComponent implements OnInit {

  entries: Array<Entry> = [];

  constructor(private authService: AuthService) {
  }

  ngOnInit() {
    this.authService.entries().subscribe((data: Array<Entry>) => {
      this.entries = data;
      console.log(data);
    });
  }

}

How can I navigate to same route and fire constructor to get my data from the endpoint.

Posts: 3

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 49230

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>