在angular2中设置Inmemorywebapi URL

时间:2017-07-24 08:51:53

标签: angular

我有这个in-memory-web-api,名为in-memory-data.service.ts,如下所示。

import { InMemoryDbService } from 'angular-in-memory-web-api';

export class InMemoryDataService implements InMemoryDbService {
  createDb() {
        let users = [
            {name:'shoaib', email:'shoaib2014@namal.edu.pk', father_husband:'M.Iqbal', address:'Chakwal', cnic:'3720102140677'},
            {name:'adil', email:'adil2014@namal.edu.pk', father_husband:'Malik Akil', address:'Chakwal', cnic:'3720102140678'},
            {name:'xyz', email:'xyz@namal.edu.pk', father_husband:'uvw', address:'abc', cnic:'3720102140679'}
        ];
        return users;
    }
}   

此文件存在于app文件夹的子文件夹_services中。如何设置此API的URL?

2 个答案:

答案 0 :(得分:2)

默认情况下,url会像(来自内存api文档)

This in-memory web api service processes an HTTP request and returns an Observable of HTTP Response object in the manner of a RESTy web api. It natively handles URI patterns in the form :base/:collectionName/:id?

你可以在这里找到更多细节

https://github.com/angular/in-memory-web-api

答案 1 :(得分:0)

import { HttpModule }           from '@angular/http';
import { InMemoryWebApiModule } from 'angular-in-memory-web-api';

import { InMemoryDataService}     from '../app/yourfilepath';
@NgModule({
 imports: [
   HttpModule,
   InMemoryWebApiModule.forRoot(InMemoryDataService),
   ...
 ],
 ...
})
export class AppModule { ... }