Angular 2 - Ansicht wird nach Modelländerungen nicht aktualisiert

Ich habe eine einfache Komponente, die alle paar Sekunden eine REST-API aufruft und einige JSON-Daten zurückerhält. Ich kann anhand meiner Protokollanweisungen und des Netzwerkverkehrs feststellen, dass sich die zurückgegebenen JSON-Daten ändern und mein Modell aktualisiert wird. Die Ansicht ändert sich jedoch nicht.

Meine Komponente sieht so aus:

import {Component, OnInit} from 'angular2/core';
import {RecentDetectionService} from '../services/recentdetection.service';
import {RecentDetection} from '../model/recentdetection';
import {Observable} from 'rxjs/Rx';

@Component({
    selector: 'recent-detections',
    templateUrl: '/app/components/recentdetection.template.html',
    providers: [RecentDetectionService]
})



export class RecentDetectionComponent implements OnInit {

    recentDetections: Array<RecentDetection>;

    constructor(private recentDetectionService: RecentDetectionService) {
        this.recentDetections = new Array<RecentDetection>();
    }

    getRecentDetections(): void {
        this.recentDetectionService.getJsonFromApi()
            .subscribe(recent => { this.recentDetections = recent;
             console.log(this.recentDetections[0].macAddress) });
    }

    ngOnInit() {
        this.getRecentDetections();
        let timer = Observable.timer(2000, 5000);
        timer.subscribe(() => this.getRecentDetections());
    }
}

Und meine Ansicht sieht so aus:

<div class="panel panel-default">
    <!-- Default panel contents -->
    <div class="panel-heading"><h3>Recently detected</h3></div>
    <div class="panel-body">
        <p>Recently detected devices</p>
    </div>

    <!-- Table -->
    <table class="table" style="table-layout: fixed;  word-wrap: break-word;">
        <thead>
            <tr>
                <th>Id</th>
                <th>Vendor</th>
                <th>Time</th>
                <th>Mac</th>
            </tr>
        </thead>
        <tbody  >
            <tr *ngFor="#detected of recentDetections">
                <td>{{detected.broadcastId}}</td>
                <td>{{detected.vendor}}</td>
                <td>{{detected.timeStamp | date:'yyyy-MM-dd HH:mm:ss'}}</td>
                <td>{{detected.macAddress}}</td>
            </tr>
        </tbody>
    </table>
</div>

Ich kann aus den Ergebnissen von @ sehconsole.log(this.recentDetections[0].macAddress) dass das recentDetections-Objekt aktualisiert wird, aber die Tabelle in der Ansicht sich nie ändert, es sei denn, ich lade die Seite neu.

Ich kämpfe um zu sehen, was ich hier falsch mache. Kann jemand helfen

Antworten auf die Frage(10)

Ihre Antwort auf die Frage