I can't bind my Angular HTML to my devices
array because there is a mismatch between what I am expecting the object to look like. I want to bind to device.modelName
but it fails because the object I'm actually getting back has the property ModelName
without camelCase!
Googling a solution I saw that I should use type assertion so I did by adding <DeviceStatus[]>
resulting in the line <DeviceStatus[]>response.json());
in my component class. Unfortunately this didn't seem to change anything.
Why does it seem like my json object isn't being mapped properly?
My model interface:
export interface DeviceStatus {
deviceId: string;
modelName: string;
}
My component:
export class FetchDataComponent {
public devices: Observable<DeviceStatus[]>;
constructor(http: Http) {
this.devices =
http.get('api/Devices')
.map((response: Response) => <DeviceStatus[]>response.json());
this.devices.subscribe(x => console.log(x));
}
}
The result in Chrome console:
(2) [Object, Object]
0: Object
DeviceId: "1"
ModelName: "Model Name"
...