Am new for angular2, i'm http.get("url") method get json type data, how to set typescript datatype(below see-(this is part of response data))in angular2 object.
this is part of response data:
{
"items":[
{
"aliases":[
"http://www.xyz.in",
"http://facebook.xyz.in"
],
"styling":{
"tag_background_color":"#E0EAF1",
"tag_foreground_color":"#3E6D8E",
"link_color":"#0077CC"
},
"related_sites":[
{
"relation":"meta",
"api_site_parameter":"meta.xyz",
"site_url":"http://met.xyz.in"
},
{
"relation":"chat",
"name":"Stack Overflow Chat"
}
],
"markdown_extensions":[
"Prettify"
],
"launch_date":1221436800,
"closed_beta_date":1217462400,
"site_state":"normal",
"favicon_url":"https://cdn.sstatic.net/Sites/xyz/img/favicon.ico",
"name":"Stack Overflow",
"site_type":"main_site"
}]}
i have create to:
import {Related_sites,Styling} from "./all_type1";
import {Injectable} from "@angular/core";
export interface Items{
aliases:any;
styling:Styling[];
related_sites:Related_sites[];
markdown_extensions:any;
launch_date: number;
closed_beta_date: number;
site_state: string;
favicon_url: string;
name: string;
site_type: string;}
and
export interface Styling {
tag_background_color: string;
tag_foreground_color: string;
link_color: string;
}
export interface Related_sites{
related_sites:[
{
relation:string;
api_site_parameter:string;
site_url:string;
},
{
relation:string;
name:string;
}]
}
is this the right way or not?? any one help...
as Items[]only tells the IDE that it is safe to assume thatdataisItems[], but it doesn't have any effect before runtime if it isn't. At runtime it will cause an error when that data actually doesn't conform to the interface.