相关疑难解决方法(0)

将httpClient答案转换为模型对象[Angular 6]

我有一个关于Angular 5 httpClient的问题.

这是一个带有方法foo()的模型类,我希望从服务器接收

export class MyClass implements Deserializable{
  id: number;
  title: string;

  deserialize(input: any) {
    Object.assign(this, input);
    return this;
  }

  foo(): string {
    // return "some string conversion" with this.title
  }
}
Run Code Online (Sandbox Code Playgroud)

这是我的服务请求:

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { MyClass } from './MyClass';

@Injectable({
  providedIn: 'root',
})
export class MyClassService {

  constructor(private http: HttpClient) {
  }

  getMyStuff(): Observable<MyClass[]> {
    // this is where I hope …
Run Code Online (Sandbox Code Playgroud)

typescript angular angular6

13
推荐指数
1
解决办法
1万
查看次数

标签 统计

angular ×1

angular6 ×1

typescript ×1