手动触发内存中的角度web-api

时间:2017-08-28 18:53:57

标签: angular

我看到根据您的文档启用它是非常简单的启用/禁用in-memory-web-api非常简单。我一直在玩测试仪可以从下拉模式启用/禁用某些模拟服务的场景。

我无法从我的组件订阅该服务。

export class InMemPatientService implements InMemoryDbService {
  createDb() {
     const patients = [
        {
            id: 1,
            patient: "Adewumi, Anice (56, F)",
            facility: "Brighton",
            datesValid: "07/07/17 - 07/07/18",
            typeD: "Tx Hemo (CHG)",
            order: "Frequency 3 times per week; Treatment Time 4 hours 10 minutes per week (250)"
        },
        {
            id:2,
            patient: "Bowman, Jackson (56, M)",
            facility: "Brighton",
            datesValid: "06/07/17 - 07/07/18",
            typeD: "Tx Hemo (CHG)",
            order: "Frequency 3 times per week; Treatment Time 4 hours 10 minutes per week (250)"
        }
     ];
     return {patients}; ***//also attempting return Observable.of({patients}) ******
  }

}

我希望订阅就像将服务注入组件并执行

一样简单
constructor(private modalService: NgbModal,
          private memPatientService: InMemPatientService) {}

 runMockServiceCheck() {
     if (!this.mockServiceCheck) {
     console.log("false");
  } else {
    this.memPatientService
     .createDb()
       .subscribe(patients => {
        this.patients = patients;
      }, 
      error => this.errorMessage = <any>error);
  }
}

但是,我收到错误

Property 'subscribe' does not exist on type '{ patients: ({ id: number; patient: string; facility: string; datesValid: string; typeD: string; ...'.

我不确定我是否正在尝试执行该库不适用的内容,或者如果我在代码中遗漏某些内容以启用此功能。

**我也尝试过 Observable.of({病人}),但是我收到任何错误

 this.patients 

订阅内

0 个答案:

没有答案