i can’t add JSON parameters to my back button with this code :
constructor(private navCtrl: NavController,private platform: Platform,private route: ActivatedRoute, public formBuilder: FormBuilder,private myStorage: StorageService,private router: Router, private userService: UserCrudService, private dataService: DataService, private authService: AuthService) {
this.formPresence= this.formBuilder.group({
presM: false,
presA: false,
typeAbsence: null // Ajout du nouveau contrôle de formulaire
});
console.log(this.formPresence.value);
// this.token=localStorage.getItem('token');
//let decoded = jwt_decode(this.token);
//console.log(decoded);
try {
this.backButtonSubscription =this.platform.backButton.subscribeWithPriority(5, () => {
console.log(this.parameters);
const param=JSON.stringify(this.parameters);
console.log(param);
this.router.navigate(['/accueil', {param}])
});
}
catch (error :any){
console.log(error.toString());
}
and
import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import {ActivatedRoute, Router} from "@angular/router";
import {ScreenOrientation} from "@ionic-native/screen-orientation/ngx";
import jwt_decode from "jwt-decode";
import {NavController, ToastController} from "@ionic/angular";
import {FormGroup} from "@angular/forms";
import {ExceptionCode} from "@capacitor/core";
import {DataService} from "../services/DataService/data.service.ts.service";
import {AutoUnsubscribe} from "../decorator/auto-unsuscribe.decorator";
import {AuthService} from "../services/AuthService/auth-service.service";
@AutoUnsubscribe()
@Component({
selector: 'app-accueil',
templateUrl: './accueil.page.html',
styleUrls: ['./accueil.page.scss'],
})
export class AccueilPage implements OnInit {
formPresence: FormGroup ;
public date: string;
public username: string;
private parameters: any ;
private selectedDates :[];
private maDate: Date ;
private token: string ;
private parametres: string;
constructor(
private navCtrl: NavController,
private route: ActivatedRoute,
private router: Router,
private screenOrientation: ScreenOrientation,
private toastController: ToastController,
private dataService: DataService,
private authService: AuthService // Retirez le point-virgule
) {
this.token = localStorage.getItem('token');
}
ngOnInit() {
console.log(this.authService.isLoggedIn());
if (this.authService.isLoggedIn()) {
this.token = localStorage.getItem('token');
this.username = localStorage.getItem('username')
try {
console.log(this.route.snapshot.params.param);
this.parameters =JSON.parse(this.route.snapshot.params.param);
}catch (error :any){
console.error(error.toString())
}
console.log(this.parameters);
try{
this.username = this.parameters.username;
}
catch(error :any){
console.error(error)
}
try{
this.selectedDates = this.parameters.selectedDates;
}
catch (error :any){
console.error(error.toString())
}
this.maDate = new Date();
console.log(this.selectedDates);
} else {
this.router.navigate(['login']);
}
}
Expected Behavior
not to have undefined in my previous view
Steps to Reproduce
read others github
Code Reproduction URL
No response
Ionic Info
lastest version
package.json:
{
"name": "FacilNdf",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "https://ionicframework.com/",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular-devkit/build-angular": "^17.1.0",
"@angular-devkit/core": "^17.1.0",
"@angular-eslint/eslint-plugin": "^17.2.0",
"@angular/animations": "^17.1.0",
"@angular/cdk": "^17.1.0",
"@angular/common": "^17.1.0",
"@angular/core": "^17.1.0",
"@angular/forms": "^17.1.0",
"@angular/platform-browser": "^17.1.0",
"@angular/platform-browser-dynamic": "^17.1.0",
"@angular/router": "^17.1.0",
"@auth0/angular-jwt": "^5.2.0",
"@awesome-cordova-plugins/calendar": "^6.6.0",
"@babel/runtime": "^7.23.8",
"@capacitor-community/http": "^1.4.1",
"@capacitor/app": "^5.0.6",
"@capacitor/camera": "^5.0.8",
"@capacitor/core": "^5.6.0",
"@capacitor/filesystem": "^5.2.0",
"@capacitor/ios": "5.6.0",
"@capacitor/keyboard": "^5.0.7",
"@capacitor/preferences": "^5.0.6",
"@ionic-native/android-permissions": "^5.36.0",
"@ionic-native/base64-to-gallery": "^5.36.0",
"@ionic-native/camera": "^5.36.0",
"@ionic-native/core": "^5.36.0",
"@ionic-native/ftp": "^5.36.0",
"@ionic-native/native-storage": "^5.36.0",
"@ionic-native/screen-orientation": "^5.36.0",
"@ionic/angular": "^7.6.5",
"@ionic/angular-toolkit": "^11.0.0",
"@ionic/cordova-builders": "^11.0.0",
"@ionic/storage-angular": "^4.0.0",
"@jridgewell/sourcemap-codec": "^1.4.15",
"@npmcli/fs": "^3.1.0",
"@types/ssh2": "^1.11.18",
"@types/ssh2-sftp-client": "^9.0.3",
"@typescript-eslint/parser": "^6.19.0",
"angular-calendar": "^0.31.0",
"bcryptjs": "^2.4.3",
"crypto-js": "^4.2.0",
"date-fns": "^3.2.0",
"ion7-calendar": "^3.6.29",
"ionic-native-sftp-leapfroggr": "^1.0.1",
"ionicons": "^7.2.2",
"jwt-decode": "^4.0.0",
"moment": "^2.30.1",
"mongodb": "^6.3.0",
"ngx-toastr": "^18.0.0",
"npm-check-updates": "^16.14.12",
"odometer": "^0.4.8",
"path-exists": "^5.0.0",
"rxjs-compat": "^6.6.7",
"rxjs-observable": "^0.0.7",
"serve": "14.2.1",
"signature_pad": "^4.1.7",
"sweetalert2": "^11.10.3",
"swiper": "^11.0.5",
"ts-md5": "^1.3.1",
"tslib": "^2.6.2",
"uuid": "^9.0.1",
"zone.js": "^0.14.3"
},
"description": "application mobile facile",
"devDependencies": {
"@angular/cli": "17.1.0",
"@capacitor/android": "5.6.0",
"@capacitor/cli": "^5.6.0",
"@types/node": "^20.11.5",
"cordova-android": "^12.0.1",
"cordova-plugin-device": "2.1.0",
"cordova-plugin-ionic-keyboard": "^2.2.0",
"cordova-plugin-ionic-webview": "^5.0.1",
"cordova-plugin-splashscreen": "6.0.2",
"cordova-plugin-statusbar": "^4.0.0"
},
"cordova": {
"plugins": {
"cordova-plugin-statusbar": {},
"cordova-plugin-device": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-ionic-webview": {},
"cordova-plugin-ionic-keyboard": {}
},
"platforms": [
"android"
]
}
}
reference to this topic :bug: impossible to pass JSON parameters with back button · Issue #28852 · ionic-team/ionic-framework · GitHub
could you help me ?
Cordially
1 post - 1 participant
Read full topic