我试着做一个*ngFor,但看起来是这样的:ng-reflect for-of。当使用de日志时,变量工作良好。
代码html:
<table class="table">
<thead class="thead-dark">
<tr>
<th *ngFor="let cabecera of cabeceras">hello {{ cabecara }}</th>
</tr>
</thead>
</table>代码.ts:
import { Component, OnInit, Input } from '@angular/core';
import { ProductoService } from '../../services/Producto.Service';
@Component({
selector: 'tabla-producto',
templateUrl: './tabla-producto.component.html'
})
export class TablaProductoComponent implements OnInit {
cabeceras: string[];
@Input() productos: any[] = [];
constructor(private producto: ProductoService) {
this.cabeceras = ['Id Producto', 'Nombre', 'Precio', 'Stock', 'Nombre Categoria'];
}
// Todo lo que pongamos aquí abajo, se ejecutará al cargar la página
ngOnInit(){
this.producto.getProducto().subscribe((data: any) => {
// console.log("imprime objeto data")
// console.log(data);
this.productos = data;
console.log("imprime objeto productos")
console.log(this.productos);
});
}
}图像控制台

发布于 2020-03-23 03:51:00
你有个打字错误
<table class="table">
<thead class="thead-dark">
<tr>
<th *ngFor="let cabecera of cabeceras">hello {{ cabecara }}</th>
</tr>
</thead>
</table>你写的是cabecara而不是cabecera
https://stackoverflow.com/questions/60807584
复制相似问题