showing results for - "angular view not changing on model"
Alberto
18 Mar 2017
1import {Component, OnInit, NgZone} from 'angular2/core';
2
3export class RecentDetectionComponent implements OnInit {
4
5    recentDetections: Array<RecentDetection>;
6
7    constructor(private zone:NgZone, // <== added
8        private recentDetectionService: RecentDetectionService) {
9        this.recentDetections = new Array<RecentDetection>();
10    }
11
12    getRecentDetections(): void {
13        this.recentDetectionService.getJsonFromApi()
14            .subscribe(recent => { 
15                 this.zone.run(() => { // <== added
16                     this.recentDetections = recent;
17                     console.log(this.recentDetections[0].macAddress) 
18                 });
19        });
20    }
21
22    ngOnInit() {
23        this.getRecentDetections();
24        let timer = Observable.timer(2000, 5000);
25        timer.subscribe(() => this.getRecentDetections());
26    }
27}
28
similar questions
queries leading to this page
angular view not changing on model