I am making requests to an API of mine made in Laravel that gives me a JSON, which maps to a table and when trying to load with DataTables shows the data but says below Not data available in table
.
This is the html of the table view
<div class="col-md-12">
<div *ngIf="rol">
<!-- <a (click)="Roles()" class="btn btn-danger">cargar lista</a> -->
<table datatable="ng" class="table table-hover" id="example">
<thead>
<!-- <tr>
<th>
<div class="botones" >
<a [routerLink]="['/dashboards/addroluser']" class="btn btn-md btn-warning">Add Rol
</a>
</div>
</th>
</tr> -->
<tr>
<th style="width: 1%" class="text-center">No.</th>
<th>Name rol</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr align="left" *ngFor="let producto of data">
<td>
{{producto.id}}
</td>
<td>{{producto.denominacion}}</td>
<td>
<div class="botones" *ngIf="confirmado != producto.id">
<a (click)="borrarConfirm(producto.id);" class="btn btn-md btn-danger">Borrar</a>
</div>
<div class="botones" *ngIf="confirmado== producto.id">
<a (click)="onDeleteProducto(producto.id);" class="btn btn-md btn-danger">Quiero eliminarlo</a>
<a (click)="cancelarConfirm();" class="btn btn-md btn-warning">Cancelar</a>
</div>
</td>
<td>
<div class="botones" >
<a [routerLink]="['/dashboards/editrol', producto.id]" class="btn btn-md btn-warning">Editar</a>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
and there is the q component that calls a service:
export class ViewComponent implements OnInit{
public title : string;
public rol : Roles;
public data: any=[];
constructor(
private _router: Router,
private _route : ActivatedRoute,
private _service : StrService
){
this.title='List Roles';
this.rol = new Roles('');
}
ngOnInit()
{
console.log('View Roles initialized');
// setTimeout(function()
// {
// this.Roles();
// },3000);
}
Roles()
{
this._service.getRoles().subscribe(
response=>{
if (response.code==200)
{
this.data = response.datos;
// setTimeout(function(){
// this.rol=response.datos;
// },5000);
console.log('laaaaaaaaaaaaaaaaaaaaaaaaa'+this.data);
// console.log(this.rol);
}
},error=>{
console.log(<any>error)
});
}