【发布时间】:2020-11-17 23:51:35
【问题描述】:
我正在使用 ionic 5 和 angular 9。并使用 angular Router 在页面之间移动。但这给我带来了一个问题,在离子中,ngOnInit 不再被调用。我知道 ionic 中有一个 NavController 以及它抛出的生命周期事件......但我需要知道是否有一种方法可以使用角度路由器并再次调用 ngOnInit。
一些代码来说明...
第 1 页:
goToPerson(person){
this.router.navigateByUrl("/personProfile", {state:person, replaceUrl:true});
}
第 2 页:
ngOnInit() {
this.person = this.router.getCurrentNavigation().extras.state as Person;
if(this.person.photo != null){
this.photoPerfil = environment.img_url + this.person.photo.fileName;
}else{
this.photoPerfil = "../../../assets/images/person.png";
}
}
【问题讨论】: