Answer the question
In order to leave comments, you need to log in
Why isn't subscribe initialized when visiting the page again?
Basically there is an app. 2 pages ..... when I'm on the main page and go to 2 .... everything is ok ... but when I go to the main page and back from the second page, the function from the service does not start again ... the page becomes empty ... and the function does not work in ngOnInit
// Services
export class CommonDataService {
private question = new Subject<any>();
changeQuestion(boolean): void {
this.question.next(boolean);
}
getQuestion(): Observable<any> {
return this.question.asObservable();
}
}
export class ApiService {
getQuestionsData(params?: string) {
params = params || '';
if (params) {
params = '?' + params;
}
return this.getTemplate('/q' + params, {}).subscribe((data: any) => {
this.commonData.changeQuestion(data);
});
}
}
ngOnInit() {
apiData: Subscription[] = [];
const langSub = this.commonData.getQuestion().subscribe((data: any) => {
});
this.apiData.push(langSub);
}
ngOnDestroy() {
this.apiData
.forEach(s => s.unsubscribe());
// }
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question