I’m trying to populate a table with data from an Oracle database locally. The database loads correctly in TypeScript, and it provides the data, but it doesn’t display in the HTML.
Code:
app.component.ts
import { CommonModule } from '@angular/common';
import { Component, OnInit } from '@angular/core';
import { runQuery } from './database';
import { ActivatedRoute, Router } from '@angular/router';
export interface Product {
ID: number;
NAME: string;
DESCRIPTION: string;
PRICE: number;
CATEGORY: string;
}
@Component({
imports: [CommonModule],
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
standalone: true
})
export class AppComponent implements OnInit {
title = 'proyecto';
data: Product[] = [];
loading: boolean = true;
ngOnInit() {
this.loadData();
}
constructor(private router: Router, private route: ActivatedRoute) {}
async loadData() {
try {
const result = await runQuery();
if (result !== undefined) {
console.log(result);
this.data = result;
this.loading = false;
} else {
console.error('Error');
}
} catch (error) {
console.error( error);
}
}
}
app.component.html
<h1>Database Oracle</h1>
<table >
<thead>
<tr>
<th>ID</th>
<th>NAME</th>
<th>DESCRIPTION</th>
<th>PRICE</th>
<th>CATEGORY</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let product of data">
<td>{{ product.ID }}</td>
<td>{{ product.NAME }}</td>
<td>{{ product.DESCRIPTION }}</td>
<td>{{ product.PRICE }}</td>
<td>{{ product.CATEGORY }}</td>
</tr>
</tbody>
</table>
Issue: Data from the Oracle database is not being loaded/displayed in the HTML
the data loads in the AppComponent, it doesn’t appear in the HTML. Could it be that the HTML is rendered before the AppComponent? What could be a solution?
I have no errors
just this:
browser-external:util:9 Module “util” has been externalized for browser compatibility. Cannot access “util.inspect” in client code
but i dont think is that
thankkk
user24682941 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1