I have read several answers on stack overflow regarding this issue but I seem not to get a solution
I have simple records in database and I would like to show them using an angular theme .
My code is as below
table-list.component.ts
import { Component, OnInit } from '@angular/core';
import { Injectable } from '@angular/core';
import { UserDetailService } from './../shared/user-detail.service';
import { UserDetail } from './../shared/user-detail.model';
import { DetailsService } from './../details.service';
import { ToastrService } from 'ngx-toastr';
//import { UsersService } from '../users.service'
@Component({
selector: 'app-table-list',
templateUrl: './table-list.component.html',
styleUrls: ['./table-list.component.css']
})
export class TableListComponent implements OnInit {
// users: any;
//currentUser = null;
//currentIndex = -1;
//title = '';
constructor(private service: UserDetailService,private toastr: ToastrService) { }
ngOnInit(): void {
//this.retrieveUsers();
this.service.refreshList();
}
app.module.ts
declarations: [
AppComponent,
AdminLayoutComponent
],
providers: [UserDetailService,
DetailsService],
bootstrap: [AppComponent]
})
user-detail.service.ts
import { Injectable } from '@angular/core';
import { UserDetail } from './user-detail.model';
import { HttpClient } from "@angular/common/http";
import { ToastrService } from 'ngx-toastr';
@Injectable({
providedIn: 'root'
})
export class UserDetailService {
formData:UserDetail;
list :UserDetail[];
readonly rootURL = 'http://localhost:19199/api'
constructor(private http: HttpClient) { }
refreshList(){
let url="http://localhost:19199/api/Users"
this.http.get(url)
.toPromise().then(res =>this.list =res as UserDetail[]);
}
array = [
{
guid: '900ea552-ef68-42cc-b6a6-b8c4dff10fb7',
age: 32,
name: 'Powers Schneider',
},
{
guid: '880381d3-8dca-4aed-b207-b3b4e575a15f',
age: 25,
name: 'Adrian Lawrence',
},
{
guid: '87b47684-c465-4c51-8c88-3f1a1aa2671b',
age: 32,
name: 'Boyer Stanley',
},
]
}
This is the code for html page
table-list.component.html
<tbody>
<tr *ngFor='let element of array'>
<td>{{element.name}}, {{element.age}}</td>
<!-- <td>{{user.Address}}</td>
<td>{{user.City}}</td> -->
</tr>
Neither it shows the array data i have defined neither it shows the data from database.
