Differences between getRootNav () and navCtrl () Methods

Can you tell me what are the differences below the two methods? What moment should I use?

book.ts

this.app.getRootNav().push('FromBook', { bookId: this.data.id })

this.navCtrl.push('FromBook', { bookId: this.data.id });

When we use internal components like below, sometimes it works. This is sometimes not the case. Why is this behavior different from the two navigation methods?

author-page.html

<div>
        <book *ngFor="let book of authorData?.books" [data]="book"></book>
</div>
+4
source share
1 answer

Both methods add a new page to the current Nav component, the only difference is which Nav Controller .

, Nav. , , this.navCtrl.push(ThePage), , , , - . , Nav, Nav .

this.app.getRootNav().push(ThePage), Nav , , , , Nav, Nav .

, , (popover, modal, alert ..)

:

Overlay

, (popover, , ..)? popover . popover NavController , getRootNav().

import { Component } from '@angular/core';
import { App, ViewController } from 'ionic-angular';

@Component({
    template: `
    <ion-content>
      <h1>My PopoverPage</h1>
      <button ion-button (click)="pushPage()">Call pushPage</button>
     </ion-content>
    `
  })
  class PopoverPage {
    constructor(
      public viewCtrl: ViewController
      public appCtrl: App
    ) {}

    pushPage() {
      this.viewCtrl.dismiss();
      this.appCtrl.getRootNav().push(SecondPage);
    }
  }
+4

Source: https://habr.com/ru/post/1680399/


All Articles