Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

angular view not changing on model

import {Component, OnInit, NgZone} from 'angular2/core';

export class RecentDetectionComponent implements OnInit {

    recentDetections: Array<RecentDetection>;

    constructor(private zone:NgZone, // <== added
        private recentDetectionService: RecentDetectionService) {
        this.recentDetections = new Array<RecentDetection>();
    }

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

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

PREVIOUS NEXT
Code Example
Javascript :: get call log in react native with filter android 
Javascript :: moment js formating to one day less using zulu time 
Javascript :: Format Mathjax 
Javascript :: node middle code for server 
Javascript :: axios get request body 
Javascript :: NodeJS: Good way to write Multiple API Calls in serial 
Javascript :: angular 10 filter date time 
Javascript :: create a virtual reality website using react js 
Javascript :: async loop with mongoose 
Javascript :: npm package al dar una direccion se obtienen las coordenadas longitud y latitud 
Javascript :: how to filter data in javascript object 
Javascript :: How to determine dropdown should show upward or downward direction 
Javascript :: Failed: Template parse errors: There is no directive with "exportAs" set to "ngModel" karma 
Javascript :: how to remove elevation tab bar react native 
Javascript :: how to mask credit card number in javascript 
Javascript :: url(image loacation) give a class 
Javascript :: pass image as props vue vuetify 
Javascript :: copy Konva Transform object 
Javascript :: browser extensions settings page 
Javascript :: add multiple parameters js 
Javascript :: enum in javascript es6 
Javascript :: reduce example 
Javascript :: Array-multiple test case 
Javascript :: Function Recurser / Infinit Calling 
Javascript :: isPalindrome 
Javascript :: nestjs optional guard 
Javascript :: remove json parameter 
Javascript :: remove post via ajax 
Javascript :: desc sorting in array of objects javascript 
Javascript :: EventEmitter to emit a custom event 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =