0

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!!

2
  • have you tried printing resp.blocks if it has a value? Commented Mar 7, 2018 at 3:17
  • Yes! It has new values. Commented Mar 7, 2018 at 3:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.