我在旧的ionic 3中具有以下代码,目前我必须迁移到ionic5。我在Google上进行了搜索,但直到发现它令人困惑为止。
在我的HTML(click)=“ onAllergiesDetailsClicked(medicalAlertGroup,'Medical Alert')”
在我的TS文件中onAllergiesDetailsClicked(allergiesGroupLists,pageTitle){this.navCtrl.push(AllergiesGroupListPage,{allergiesGroupList:allergiesGroupLists,pageTitle:pageTitle});}
在我的AllerhiesGroupList页面中让allergiesGroupList:PatientAllergiesGroup = this.navParams.get('allergiesGroupList');this.pageTitle = this.navParams.get('pageTitle');this.patientAllergiesLists =(allergiesGroupList.patientAllertList.sort(this.sortingDate));
首先创建一个名为data的服务:
export class dataService {
setvalue:any;
constructor(){}
setDestValue(param){
this.setvalue = param;
}
getDestValue(){
return this.setvalue;
}
}
页面中的第二件事,您需要从以下位置发送数据:
import { Router } from '@angular/router';
import {DataService} from 'put service path here';
constructor(private dataService:DataService,private router:Router...)
onAllergiesDetailsClicked(allergiesGroupLists, pageTitle){
this.dataService.setDestValue({ allergiesGroupList: allergiesGroupLists, pageTitle: pageTitle });
this.router.navigate(["name of page to navigate to as it is named in app-routing"]);
}
并在页面中将其路由到:
import {DataService} from 'put service path here';
constructor(private dataService:DataService...){
let data = this.dataService.getDestValue();
this.pagetitle = data.pageTitle;
this.grouplist = data.allergiesGroupList;
}
就这些。