Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

129
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda