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

256
Vistas
Access Json Object return from express js with angular html template

I am trying to access JSON from angular html template. But it is not returning results. Simply showing Object or error by modification of code.

server.js

response.status(200).json(results.rows);

product.component.ts

export class ProductsComponent implements OnInit {
  products = {};
  usersJson: any[]=[];

  constructor(private service: Service) {

   }

  ngOnInit(): void {
    this.service.getResult().subscribe((data: JSON)=>{
      console.log(data);
      this.products = data;
      this.usersJson = Array.of(data);
      console.log(this.products);
    }) 
  }

data

data = [
 {product_id: 1, product_name:"Phone"},
 {product_id: 2, product_name:"laptop"}
]

product.component.html

<p>{{ products}}</p>
<h1>Product</h1>
<p>{{ products[0].product_id}}</p>
<p>{{usersJson[0]}}</p>
<p>{{usersJson[0].product_id}}</p>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try to use json pipe and '.?' notation to ensure that will not be problems with undefined fields:

<p>{{ products | json }}</p>
<h1> Product </h1>
<p>{{ products[0] != null ? ( products[0]?.product_id | json ) : 'N/A' }}</p>
<p>{{ usersJson[0] != null ? ( usersJson[0] | json ) : 'N/A' }}</p>
<p>{{ usersJson[0]?.product_id }}</p>

NOTE: If product_id is a number/string and not an object, change

( products[0]?.product_id | json ) 

to

( products[0]?.product_id )  [just delete the json pipe in that line]
about 4 years ago · Juan Pablo Isaza Denunciar
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