I tried this answer and also this one, but I couldn't make it work.
I have this:
HTML:
<span *ngFor="let block of blocks; let i = index; trackBy: trackByFn">
{{block.description}}:
</span>
Component:
@Component({
moduleId: module.id,
styleUrls: [ 'component.css' ],
templateUrl: 'component.html'})
export class UserComponent implements OnInit {
blocks: any = [];
constructor(private userService: UserService) {}
ngOnInit(): void {
this.loadCourse();
}
private loadCourse(){
this.http.get(url + parseInt(localStorage.getItem('id'))).map((response: Response) => response.json())
.subscribe(resp => {
this.blocks = resp.blocks;
});
}
trackByFn(index, item) {
return index;
}
An then, after some user interaction, I trigger this two lines:
localStorage.setItem('id','4');
this.loadCourse();
And the blocks array is updated, but the DOM is not updated, so I don't see the new descriptions in the HTML.
What's missing?
Thanks!!
resp.blocksif it has a value?