Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property 'push' does not exist on type 'NavController' in Angular

I'm building Ionic app and I need to navigate to another page when I click on the button and pass the variable, but for some reason this.navCtrl.push() is not working.

What might be the issues? Thank you in advance.

HomePage:

import { Component, Input, Output, EventEmitter } from '@angular/core';
import { CurrentWeatherPagePage } from '../current-weather-page/current-weather-page.page';
import { NavController, NavParams } from '@ionic/angular';

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage {

  constructor(public navCtrl:NavController){}

  cityName = ''
  logForm() {
    console.log(this.cityName);
    this.navCtrl.push(CurrentWeatherPagePage, this.cityName);
  }

  

}
like image 857
Serget Avatar asked Sep 08 '26 12:09

Serget


1 Answers

You have to use navCtrl.navigateForward and if you need to pass parameters you can do this

this.navCtrl.navigateForward(<URL>, { state: { <DATA> } } );

Then in the other view, in the constructor, do this

data: any = null ;

constructor(private router: Router) { 
    this.data = this.router.getCurrentNavigation()?.extras?.state;
}
like image 111
Talon Avatar answered Sep 10 '26 02:09

Talon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!