angular2 map data as specific object type

前端 未结 4 1984
梦如初夏
梦如初夏 2021-01-04 13:50

I created a very simple app based on the Angular2 tutorial.

To start, I have a very simple \"Book\" model:

 /**
 * book model
 */
export class Book          


        
4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-04 14:21

    I think you should declare an interface Book instead of class book:

    export interface Book {
        public id;
        public title:string;
        public pages:Array;
    }
    

    In your service:

    //get one record
    return this._http.get('getBook/1')
            .map(function(res){
                return  res.json();
            });
    
    //get multi record
    return this._http.get('getBooks')
            .map(function(res){
                return  res.json();
            });
    

提交回复
热议问题