I have a function called getPuzzle() that calls an API to get data. I want to use that data to modify a div. The issue is that this is all done in the constructor and so the html hasn't been loaded yet.
So I put the code that modifys the html into ionViewDidEnter, however then it runs before the call to the API and it's missing the data this.puzzle
How do I not run this code until the HTML has loaded completely and AFTER the API call?
ngOnInit() {
this.getPuzzle();
}
getPuzzle() {
//Get puzzle info
this.puzzlesService.getPuzzle().subscribe((data) => {
this.puzzleType = this.puzzlesService.puzzleType;
this.puzzle = this.puzzlesService.puzzle;
});
}
ionViewDidEnter() {
//Set first tab
if (this.puzzleType == 'text') {
new Vara("#text", "assets/fonts/vara/Satisfy/SatisfySL.json", [{
text: this.puzzle,
delay: 2000,
x: 2
}], {
fontSize: 25,
strokeWidth: 1.5,
duration: 15000,
color: "black"
});
}
}
this.puzzle = this.puzzlesService.puzzle; });after this line.puzzlesService.getPuzzle(), then ignoring the data? Seems fishy! Also, why is this component duplicating at least 3 properties of a service you have access to?getPuzzle,puzzleType, andpuzzleexist for both this component and the puzzlesService. Is there a reason for that?