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

128
Views
How do i update the existed user input using Specific User ID in angular

i m stuck on the update of the user input how do i edit or update the default value entering User ID //user service import { Injectable } from '@angular/core';

 @Injectable({
      providedIn: 'root'
    })
    export class UserService {
      userArray : any[] =[];
      constructor() { }
      public getUsers() : any[]{
        return this.userArray;
      }
      public save(obj : any):void {
        const lastElement = this.userArray[this.userArray.length - 1];
        if(lastElement !== undefined){
           obj.id = lastElement.id+1;
        }
        else{
           obj.id = 1;
        }
        this.userArray.push(obj);
      }
    
      public delete(id: number) : void {
        for(let i = 0; i < this.userArray.length; i++) {
          let user = this.userArray[i];
          if(user.id == id) {
            this.userArray.splice(i,1);
          }
        }
      }
      public update(id:number):void {
        
          
        }
    } 

//this below is store.component.ts this is where i store the user inputs export class StoreFormComponent implements OnInit {

      constructor(private builder : FormBuilder,private service : UserService, private 
      _router:Router) { }
    
      ngOnInit(): void {
      }
      userForm : FormGroup = this.builder.group({
        id:[''],
        name : ['',[Validators.required,Validators.minLength(2), Validators.maxLength(10)]],
        gender :['',[Validators.required]],
        phone:['',[Validators.required]],
        email:['',[Validators.required]],
        address: this.builder.group({
          state:['',[Validators.required]],
          city:['',[Validators.required]],
          pin:['',[Validators.required]]
        })
      });
      
      saveForm(){
        this.service.save(this.userForm.value)
        this._router.navigate(["success",this.userForm.value.id]);
        console.log(this.userForm.value)
      }
      clear(){
        this.service.save({})
      }
    }

And this //problem update i want to edit the user input value using specific user id like when i put user id 1 update the default value or edit the new value export class UpdateComponent implements OnInit {

      constructor(private service: UserService) { }
    
      ngOnInit(): void {
      }
      id: FormControl = new FormControl('');
      update() {
        this.service.delete(this.id.value);
      }
    }
    [this is upload picture][1][output pciture][2]


  [1]: https://i.stack.imgur.com/O4Itf.jpg
  [2]: https://i.stack.imgur.com/UQAHe.jpg
about 4 years ago · Juan Pablo Isaza
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!