el modelo angular que tengo es
export class Page{
constructor(
public id: number,
public name: string,
public id_status: number,
public id_menu: number,
public position: number
){
}
}
y el json que estoy consumiendo es
{
"code": 200,
"status": "success",
"data": {
"id": 1,
"name": "inicio",
"id_status": 1,
"id_menu": 1,
"created_at": null,
"updated_at": null,
"deleted_at": null,
"position": 1,
"pages": [
{
"id": 1,
"name": "inicio222",
"id_status": 2,
"id_menu": 2,
"created_at": null,
"updated_at": null,
"deleted_at": null,
"position": 11,
"menu": {
"id": 1,
"name": "inicio",
"id_status": 1,
"created_at": null,
"updated_at": null,
"deleted_at": null,
"position": 1
}
},
{
"id": 22,
"name": "contactenos",
"id_status": 1,
"id_menu": 2,
"created_at": null,
"updated_at": null,
"deleted_at": null,
"position": 2,
"menu": {
"id": 2,
"name": "contactenos",
"id_status": 1,
"created_at": null,
"updated_at": null,
"deleted_at": null,
"position": 2
}
}
]
}
}
como puedo declarar en el modelo pages?
export class Page{
constructor(
public id: number,
public name: string,
public id_status: number,
public id_menu: number,
public position: number
){
}
}
ya intente con :
public pages: Array<any>
public pages: any
public pages: Array<Pagee> (donde Pagee es el Pagee.component.ts que tiene los atributos de pages)
ninguno funciona. me sale error page.component.ts (24,21): Supplied parameters do not match any signature of call target.
Ayuda
Nuevo comentario 24-09-2017
Ya me funciono. Si alguien le sirve tengo
en el page.component.ts la declaracion
public titulo: string;
public page: Array<Page>;
constructor(
private _pageService: PageService,
private _route: ActivatedRoute,
private _router: Router
){
this.titulo = 'Landing';
this.page = new Array<Page>();
}
modelo
export class Page{
constructor(
public id: number,
public name: string,
public id_status: number,
public id_menu: number,
public position: number,
public pages: Array<any>
){
}
}
componente service
getPage(){
this._route.params.forEach((params:Params)=>{
let id = params['id'];
this._pageService.getPage(id).subscribe(
response =>{
if(response.code == 200){
this.page = response.data;
console.log(response);
}else{
this._router.navigate(['/']);
}
},
error => {
console.log(<any>error);
}
);
});
}
y en la pagina html tengo
<li *ngFor = "let page of page.pages" >
a {{ page.name }}
</li>
Dejo el codigo por si alguien le sucede lo mismo Mil gracias