Sending params while page pop ionic 4 - ionic-framework

In Ionic 4 when I go from 1st to 2nd page with params:
let navigationExtras: NavigationExtras = {
state: {
param: 'param1'
}
};
this.router.navigateByUrl(this.router.routerState.snapshot.url + '/page', navigationExtras);
I use the above code and retrieve this data
this.router.getCurrentNavigation().extras.state;
by the above line but I also need to pass param when I go back from 2nd to 1st.
in Ionic 3 there is
this.navCtrl.getPrevious().data.param= this.param;
but I was not able to do this in ionic 4. can anyone help me with this?

Related

Get and show live data from cordova plugin in ionic 4 page

im trying to code a simple step counter app, im using this plugin (https://github.com/leecrossley/cordova-plugin-pedometer) in android to get the step counter data, so i want to get this data and show it on my ionic page (front end view), i tryed to use ngZone to refresh the object while the method subscribe to the startPedometerUpdates function, but it takes many seconds to work and sometimes stucks few seconds and then start to show the counter again...
this is my code:
steps: any = []
constructor(private ngZone: NgZone, private pedometer: Pedometer) { }
ngOnInit() {
}
getSteps(){
this.pedometer.startPedometerUpdates()
.subscribe((data: IPedometerData) => {
this.ngZone.run(() => this.steps.push(data))
});
}
my html is simple for debug the data:
<ion-content>
{{this.steps | json}}
<ion-button (click)="getSteps()">Show steps</ion-button>
</ion-content>
so i want to show the data in "real time" with something simple as posible...
thanks in advance
you can't push data in subscribe even if you using NgZone bcoz push is a function ngZone doesn't work in the function
steps: any = []
constructor(private ngZone: NgZone, private pedometer: Pedometer) {
this.getSteps();
setInterval(()=>{
console.log('read in a sec')
},1000)
}
ngOnInit() {
}
getSteps(){
this.pedometer.startPedometerUpdates()
.subscribe((data: IPedometerData) => {
this.ngZone.run(() => this.steps.push(data))
});
}

Ionic4 OneSignal open push notification redirect page

Was hoping to achieve when OneSignal push notification was being opened would redirect to a certain page in the App. Following is my code to redirect to a page called positions but it didn't seem to work. When the push notification is opened, it still opens up the url in the InAppBrowser. Any idea what went wrong? Thanks in advance.
if (this.appConfig.Onesignal_Enable == true) {
this.oneSignal.startInit(this.appConfig.OneSignal_AppID, this.appConfig.GCM_SenderID);
this.oneSignal.handleNotificationReceived().subscribe(() => {
// do something when notification is received
});
this.oneSignal.handleNotificationOpened().subscribe((data) => {
// do something when a notification is opened
// the following two lines pass data I send with the push notification so the app knows what to open
let pushaction = data.notification.payload.additionalData.action;
let pushactionvalue = data.notification.payload.additionalData.actionvalue;
// this fires up the tab-switching
this.runNotificationAction(pushaction, pushactionvalue);
});
this.oneSignal.endInit();
}
runNotificationAction(pushaction, pushactionvalue){
// this is the data passed the the other page
let data = {"action": pushaction, "value:": pushactionvalue};
this.navCtrl.navigateForward('positions');
}
Hello I'm using v4 ionic too and I achieved this with this implementation on my project:
let self = this;
var notificationOpenedCallback = async function(jsonData) {
//I use info data previous saved, but you can use jsonData
switch (self.user.role) {
case "customer":
self.router.navigate(["history-customer"]);
break;
case "provider":
self.router.navigate(["history-provider"]);
}
};
window["plugins"].OneSignal.startInit(
"0*************7",
"1*********2"
)
.handleNotificationOpened(notificationOpenedCallback)
.endInit();
window["plugins"].OneSignal.setSubscription(true);
I use
let self = this
because startInit receive a callback so is necessary to do that, in your case I don't know if inside subscribe need also use "self" and I use Router to navigate between pages.
import { Router } from "#angular/router";
And on my app-routing.module.ts
{ path: 'history-provider', loadChildren: './pages/history-provider/history-provider.module#HistoryProviderPageModule' },
{ path: 'history-customer', loadChildren: './pages/history-customer/history-customer.module#HistoryCustomerPageModule' }

Vue: How to redirect Page for each session

I am using vuejs frontend and backend nodejs.
I need to do the following:
URL paster/user/A redirects to paster/session/ghb72fvd (where wait 5 seconds is displayed) -> redirects to paster/session/cas390yd (where wait 5 seconds is displayed) -> paster/user/book5
I am thinking of having anything with paster/session/* redirects to a single page so that I need to create only one page in vue.
paster/session/ghb72fvd -> goes to page A
paster/session/cas390yd -> goes to the same page A
Any pointers in the right direction are appreciated.
Updated:
vuejs
export default {
redirectTimeout(() => this.$router.push({path: redirectSession }), 5000)
methods: {
getRedirectSession(redirectSession){
calls processSessionUrl() from nodejs
}
}
In Nodejs:has an array of [ghb72fvd, cas390yd]
If redirectSession is null choose first item in array. If redirectSession == ghb72fvd return second item
}

Tracking all screens using Google Analytics in Ionic 3 project

I'm in the middle of finalizing an Ionic 3 build and would like to add Google Analytics to it. I added it successfully and can see in GA (real time) that the app is being used however I would like to track all page/screen views. Does anyone know of way to do that?
I'm using the following plugin: https://github.com/danwilson/google-analytics-plugin
Here is the code I am using to initialize GA
initGoogleAnalytics() {
var trackingId = 'UA-114720506-2';
if (/(android)/i.test(navigator.userAgent)) { // for android
trackingId = 'UA-114720506-2';
} else if (/(ipod|iphone|ipad)/i.test(navigator.userAgent)) { // for ios
trackingId = 'UA-114720506-2';
}
//platform is injected in the Constructor
this.platform.ready().then(() => {
this.ga.debugMode();
this.ga.startTrackerWithId(trackingId).then(()=> {
console.log("GoogleAnalytics Initialized with ****** : " + trackingId);
this.ga.trackView('schedule');
this.ga.trackView('speakerList');
this.ga.trackView('map');
this.ga.trackView('social');
this.ga.trackView('exhibitors');
this.ga.enableUncaughtExceptionReporting(true)
.then((_success) => {
console.log("GoogleAnalytics enableUncaughtExceptionReporting Enabled.");
}).catch((_error) => {
console.log("GoogleAnalytics Error enableUncaughtExceptionReporting : " + _error)
});
});
});
}
Essentially adding in the GA Module and initializing with ionViewDidEnter on in every page that I wanted to track did the trick.

Ionic 3 modal display message

I have already designed the Ionic 3 modals. Now I would like to display some message ( Hello Modal ). How do I display the message inside the modal?
Below is my openModal code.
openModal() {
const myModal = this.modal.create('ModalPage');
myModal.present();
}
I would like to display the message using translate. In my case, the message will be set in en.json file, and from there I need to call the message in the HTML file. This is where I am stuck.
In ionic 1,I have something like ,
$translate(['USER_DATA']).then(function(translations) {
vm.userData=translations.USER_DATA;
}
And I will be calling vm.userData in my HTML which will display the message in modal. how do I achieve the same translate code in ionic 3
Its that simple.
import {TranslateService} from '#ngx-translate/core';
...
constructor(private translate : TranslateService)
...
this.translate.setDefaultLang('en');
This is just an overview. Please go-through this link to get a better idea.
They have clearly explained where to place en.json file and how to use it.
Happy Coding.
this.translate.get('here your message u want to translate').subscribe(res => {
const myModal = this.modal.create('ModalPage',res);
myModal.present();
})
In modalpage get the translated message by 'params.data()' and display as u want