Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

237
Views
How to use put method properly ANGULAR

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

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!