Hey there! Currently, I'm deep into developing an Angular 6 + Flask application and I've encountered a bit of a snag:
Error TS2345: Argument of type 'Object' is not assignable to parameter of type 'JSON'.
This issue arises when the following section of my code executes:
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { MessageService } from '../shared/message.service';
@Component({
selector: 'app-network-monitorer',
templateUrl: './network-monitorer.component.html',
styleUrls: ['./network-monitorer.component.css']
})
export class NetworkMonitorerComponent implements OnInit {
mqttMessageData : JSON[]=[];
coapMessageData : JSON[]=[];
xmppMessageData : JSON[]=[];
constructor(private httpClient: HttpClient, private messageService:MessageService) { }
ngOnInit() {
setInterval(()=>{
this.getMqttMessages(); },2000);
}
getMqttMessages() {
this.httpClient.get('http://127.0.0.1:5002/messages/mqtt').subscribe(data => {
this.mqttMessageData.push(data);
console.log("message :")
console.log(this.mqttMessageData.length())
console.log(data);
});
}
During the component's initialization process, a request is made to my python server to retrieve some data in JSON format back to the client. However, Angular appears to be under the impression that 'data' is an Object type and not matching it to my list of JSON.