我有一个页面,在我的ngOnInit中,我检查我到达的位置(例如,如果我从page1到达,我设置一个变量来显示html,或者从page2设置另一个变量来显示另一个html)。
ngOnInit() {
this.handleParams();
}
handleParams(){
this.isNewCustomer = JSON.parse(
localStorage.getItem(LocalstorageKeyEnum.NEW_CUSTOMER)
);
let params = this.route.snapshot.queryParams;
if (params.customerCreate === true) {
this.customerCreate = true;
}
this.isUpdate = JSON.parse(
localStorage.getItem(LocalstorageKeyEnum.IS_UPDATE)
);
}现在我注意到,这个ngOnInit()只被调用一次,所以每次我在页面中输入时,都不会检查handleParams。
我怎样才能接到ngOnInit的电话?
发布于 2022-07-21 14:39:40
你正确的问题是什么?ngOnInit是被调用过一次还是从未调用过?它是正确的,当它被称为,只要你一进入页面。也许你去localStorage的路线是错的?这只是一个简单的电话,例如:
localStorage.setItem('savePage', setUrlFromPage);
const myPage = localStorage.getItem('savePage');https://stackoverflow.com/questions/73067972
复制相似问题