Reputation: 1694
Scenario:
I have an Ionic 3 Web app, which opens for this link http://localhost:8100. I need to pass a value with the link (i.e http://localhost:8100/index.html?cell=1234567890) and the ionic app while loading the app, fetches the cell value.
What i have done:
Seriously I have no idea, where to start. I used NavParams
like this,
this.cell = this.navParams.get('cell');
and opened the app like http://localhost:8100/index.html?cell=1234567890, the app is opened successfully, but i'm getting an undefined value.
Any advice would be appreciated.
Upvotes: 1
Views: 4317
Reputation: 1694
Finally found the answer from the official documentation, IonicPage Documentation.
so i have used
@IonicPage({
segment: 'feedback/:cell'
})
and in constructor,
this.cell = this.navParams.get('cell');
now when i called this link http://localhost:8100/#/feedback/1234567890
and i get the number. everything is working fine now.
Thank you for your responses, i appreciate it.
Upvotes: 2
Reputation: 737
You could try plain old javascript. I dont think this is anything specific to ionic. And because it is not primarily navigation based then the NavParams would not work, i am guessing, you can do split
like so
let myParam = location.search.split('cell=')[1];
Ref: here
Upvotes: 0
Reputation: 737
i don't know if this is what you want but you can send params like this
this.navCtrl.push(ChildPage, {
cell: value
});
on Child page Constructor or
ionViewDidLoad() {
this.cell= this.navParams.get('cell');
console.log(this.cell);
}
Upvotes: 0