मेरे पास एक सरल घटक है जो हर कुछ सेकंड में एक रीस्ट एपी को कॉल करता है और कुछ JSON डेटा वापस प्राप्त करता है। मैं अपने लॉग स्टेटमेंट और नेटवर्क ट्रैफ़िक से देख सकता हूं कि वापस जा रहा JSON डेटा बदल रहा है, और मेरा मॉडल अपडेट किया जा रहा है, हालाँकि, दृश्य नहीं बदल रहा है।
मेरा घटक जैसा दिखता है:
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());
}
}
और मेरा विचार इस प्रकार है:
<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>
मैं उस परिणाम से देख सकता हूं console.log(this.recentDetections[0].macAddress)कि हाल ही में किए गए ऑब्जेक्ट को अपडेट किया जा रहा है, लेकिन जब तक मैं पृष्ठ को लोड नहीं करता, तब तक दृश्य में तालिका कभी नहीं बदलती है।
मैं यह देखने के लिए संघर्ष कर रहा हूं कि मैं यहां क्या कर रहा हूं। क्या कोई मदद कर सकता है?