Interfaces are found only at compile time. This allows you only to verify that the expected received data matches a specific structure. To do this, you can transfer your content to this interface:
this.http.get('...') .map(res => <Product[]>res.json());
See the following questions:
- How to create a JSON object for typescript class
- How to get Date object from json Response in typescript
You can do something similar with the class, but the main differences of the class are that they are present at runtime (constructor function), and you can define methods in them with processing. But in this case, you need to instantiate the objects in order to use them:
this.http.get('...') .map(res => { var data = res.json(); return data.map(d => { return new Product(d.productNumber, d.productName, d.productDescription); }); });
Thierry Templier Jun 06 '16 at 8:39 2016-06-06 08:39
source share