2017-07-20 11 views
2

このパッケージをインストールしました。Angular2でangular-in-memory-web-apiを使用するには?

私のモックデータクラス:

return this.http.get('api/credentials'); 

は、それが返されます。

InMemoryWebApiModule.forRoot(InMemoryDataService) 

は今、私はこのようなものを使用しよう:私はimportセクションの依存性を設定app.module.ts

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

export class InCredentialsService implements InMemoryDbService { 

    public createDb() { 

    const credentials = { 
     auth: true, 
     id: 1, 
     token: 'token', 
     grant: 'all' 
    }; 

    return credentials; 

    } 
} 

私HTTPエラー:

Response with status: 404 Not Found for URL: api/credentials

angle-in-memory-web-api rightの使い方は?

答えて

0

使用

return { credentials }; 

これは

return { credentials: credentials }; 

ための短い形式で、識別子がAPIになります。

関連する問題