我拥有的角度模型是
export class Page{
constructor(
public id: number,
public name: string,
public id_status: number,
public id_menu: number,
public position: number
){
}
}
我正在消费的json是
{
"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
}
}
]
}
}
如何在页面模型中声明?
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>
public pages: any
public pages: Array<Pagee> (donde Pagee es el Pagee.component.ts que tiene los atributos de pages)
它们都不起作用。我收到一个错误page.component.ts (24,21): Supplied parameters do not match any signature of call target.
援助
新评论 09-24-2017
它已经为我工作了。如果有人帮助我有
在 page.component.ts 声明中
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>();
}
模型
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>
){
}
}
服务组件
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);
}
);
});
}
在我的html页面中
<li *ngFor = "let page of page.pages" >
a {{ page.name }}
</li>
我留下代码以防其他人有同样的问题非常感谢
要在模型中输入角度变量,您可以这样做: