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

271
Views
método de actualización del servidor angular json

Me gustaría actualizar mi tabla sin actualizar mi página, pero no sé cómo hacerlo porque soy un principiante. En mi ejemplo, uso la mesa de material angular.

¿Cómo actualizo mi página cada vez que agrego un nuevo elemento?

Servicio

 public url: string = 'http://localhost:3000/tableInfos'; constructor(private http: HttpClient) { } getTableDetails(): Observable<PeriodicElement> { return this.http.get<PeriodicElement>(this.url); } create(name: PeriodicElement): Observable<any> { let newName = {name:name} return this.http.post<PeriodicElement>(this.url, newName); }

ts.archivo

 ELEMENT_DATA!: PeriodicElement[] displayedColumns: string[] = ['name']; dataSource = new MatTableDataSource<PeriodicElement>(this.ELEMENT_DATA); constructor(private tableService: TableService) {} ngOnInit(): void { this.get(); } get() { this.tableService.getTableDetails().subscribe((data:any) => { this.dataSource.data = data; }); } add(name: any) { this.tableService.create(name).subscribe((data:any) => { console.log(data); }); }

json

 { "tableInfos": [ { "id": 1, "name": "Hydrogen" }, { "id": 2, "name": "Helium" } ] }

interfaz

 export interface PeriodicElement { name: string; }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Simplemente use this.dataSource.data = res dentro de la función de actualización en ts.

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!