Angular Observable <objectmodel>服务返回一个字符串(而不是ObjectModel类型的对象)

时间:2018-09-19 12:21:39

标签: angular6

这是我的服务

get(id: string): Observable<PaginaModel> {
    return this.http.get<PaginaModel>('api/pagini/get/' + id);
}  

模型:

import { LinieModel } from "./linie.model";

export class PaginaModel {
    linii: LinieModel[] = [];
}

在这里我怎么称呼它:

ngOnInit() {
    this.canvas = document.getElementById('AfisareCanvas') as HTMLCanvasElement;
    this.ctx = this.canvas.getContext('2d');

    this.service.get('5b9bad0c457b4e1c70af18f8').subscribe(data =>  {
        console.log(data); //here data is string (like using stringify)
        console.log(data.linii.length); //undefined error 
    });
}   

我尝试使用JSON.parse但没有用。

0 个答案:

没有答案