I have the following code:
HTML:
<input
#title
(keyup.enter)="createPost(title)"
type="text"
class="form-control">
<ul class="list-group">
<li *ngFor="let post of posts" class="list-group-item">
{{ post.title }}
<button class="btn btn-default btn-sm" (click)="updatePost(post)">Update</button>
</li>
</ul>
Angular:
export class PostsComponent implements OnInit {
posts: any;
url = 'https://jsonplaceholder.typicode.com/posts'
constructor(private http: HttpClient) {
http.get(this.url)
.subscribe(response => {
this.posts = response;
})
}
----
updatePost(post: any) {
this.http.put(this.url + '/' + post.id, JSON.stringify({ title: 'Example' }))
.subscribe(response => {
})
}
How can I update the posts value at a given ID with the title 'Example'? If I console.log(response) it returns just a ID, not a proper value. Please help :)
It seems like they're expecting content-type application/json in request header. You can play with content-type and see result https://reqbin.com/o0tzomnc But even if you specify content-type they will return only updated field. In your case - only title field