Within my MyDevicesPage class, I am attempting to manipulate the res object and then pass it to the updateDevicesToServer method of DataService for further actions. The code compiles without errors, but at runtime, an error is thrown: ERROR Error: Uncaught (in promise): TypeError: Cannot set property 'devices' of undefined
Below are the class and associated interfaces:
export class MydevicesPage implements OnInit {
devices : Array<deviceInterface>
constructor(private deviceService : DeviceService,private route: ActivatedRoute,private router: Router, private authenticationService : AuthenticationService) { }
ngOnInit() {
this.deviceService.getDevices().then((res : devicesInterface) => {
if(res){
let data : ResUpdateDevices
data.devices = res;
this.devices = res.devices;
data.token = this.authenticationService.getToken();
this.deviceService.updateDevicesToServer(data).subscribe(res => {
console.log(res)
},err=>{
console.log(err)
});
}
})
}
goto_device(ssid : String, name : String){
this.router.navigate(['members','device',ssid,name])
}
}
ResUpdateInterface Interface
export interface ResUpdateDevices{
devices : devicesInterface
token : string
}
DeviceInterface Interface
export interface deviceInterface {
ssid : String,
name : String
}
DevicesInterface Interface
export interface devicesInterface {
devices : Array<deviceInterface>
}
Upon Console Logging res, the following output is shown:
{devices : [{ssid:"ssid", name :"name"}]}