I have the following structure:
In the app.component.ts I have a variable "valor", I want to use that variable in app-routing.module.ts
Is that possible?
I have the following structure:
In the app.component.ts I have a variable "valor", I want to use that variable in app-routing.module.ts
Is that possible?
As Sid T pointed it, you could use Nav Parameters. For instance, you would navigate like this:
app.component.ts
goToThisPage(variable) {
this.navCtrl.push(TargetPage, {
param: variable
});
}
and would retrieve the variable like this:
app-routing.module.ts
this.xyz = this.navParams.get('param');
The best way to use a common variable in any of page is to use provider. First generate provider in your project using following command :
ionic generate provider provider_name
and declare that common variable as a public in this provider like :
public test:string = "";
Now, import and inject this provider in any of page that you want to use that common variable as below :
import {provider_name} from '../..';
constructor(private testPvdr:TestProvider) {}
Now, you can use that common variable by just provider :
alert(this.testPvdr.test);