2016-09-20 19 views
2

私は、PUTメソッドのURLがメモリのWeb APIでどのように構築されるのか、app/commentList/0とします。ここでは0はcommentListのコメントIDです。サービスのPUTメソッド用にangular2-in-memory-web-apiでURLを作成するにはどうすればよいですか?

サンプルコード:DBの

updateComment(data: any):Observable<any>{ 
     const url = `${this.dataUrl}/${data.id}`; 
     return this.http.put(url, JSON.stringify(data), this.options) 
         .map(res => console.log(res)) 
    } 

サンプルコード:

import { InMemoryDbService } from 'angular2-in-memory-web-api'; 
export class CommentsData implements InMemoryDbService { 
    createDb() { 
    let commentList = [ 
     { id:1, username: 'abc', comment: 'adfasdfasdf' }, 
     { id:2, username: 'rty', comment: 'qwerqewr' }, 
     { id:3, username: 'Zaw', comment: 'poiqwer' }, 
     { id:4, username: 'weew', comment: 'asdflkjmasd' } 
    ]; 
    return {commentList}; 
    } 
} 

updateComment()方法では、私はちょうど、どのような場合は、idパラメータでURLを打つが、よ私は '名前'のように、任意の異なるパラメータを渡したいですか?

答えて

3

メモリ内Web APIデータベースにあるパラメータ名を使用できます。したがって、あなたの場合、次のようなものを使用することができます:

const url = `${this.unitDetailsUrl}/?username=${data.username}`; 
関連する問題