2

I'm wondering, how URL, for PUT method, gets constructed by in memory web api, say suppose app/commentList/0 - here 0 is the id of comment in commentList.

Sample Code of service:

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))   
    }

Sample code of DB:

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};
  }
}

In updateComment() method, I'm just hitting url with id parameter, but what if, I want to pass any different parameter, like as 'name'?

1 Answer 1

3

You can use parameter name which you have in your in-memory web api database. So in your case, something like this can be used:

const url = `${this.unitDetailsUrl}/?username=${data.username}`;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.