I'm using Ng2-Smart-Table, according to the documentation it accepts an array of objects to mount the table:
No HTML:
<ng2-smart-table [settings]="settings" [source]="data"></ng2-smart-table>
In Javascript
import { NgxDatatableModule } from '@swimlane/ngx-datatable';
import { LocalDataSource } from 'ng2-smart-table';
import { Component, OnInit } from '@angular/core';
import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database';
import {forEach} from "@angular/router/src/utils/collection";
@Component({
selector: 'app-tabela',
templateUrl: './tabela.component.html',
styleUrls: ['./tabela.component.scss']
)
export class TabelaComponent implements OnInit {
filTipo: string = 'todos';
dados: FirebaseListObservable<any>;
public solicitacoes: Array<Object>;
constructor(private db: AngularFireDatabase) {
this.dados = this.db.list('/solicitacoes');
this.dados.forEach(element => {
this.solicitacoes = element;
});
console.log(this.solicitacoes)
}
ngOnInit() {
localStorage.getItem('filTipo');
}
}
// Ng2SmartTable começa aqui
settings = {
selectMode: 'multi',
columns: {
tipo: {
title: 'Tipo',
},
localizacao: {
title: 'Localização',
},
descricao: {
title: 'Descrição',
},
data: {
title: 'Data',
},
},
actions: {
add: false,
edit: false,
delete: false,
open: true,
}
};
data = [
{
id: 1,
name: 'Leanne Graham',
username: 'Bret',
email: '[email protected]',
},
{
id: 2,
name: 'Ervin Howell',
username: 'Antonette',
email: '[email protected]',
},
{
id: 3,
name: 'Clementine Bauch',
username: 'Samantha',
email: '[email protected]',
},
{
id: 4,
name: 'Patricia Lebsack',
username: 'Karianne',
email: '[email protected]',
},
{
id: 5,
name: 'Chelsey Dietrich',
username: 'Kamren',
email: '[email protected]',
}
];
// Ng2SmartTable termina aqui
}
I'm using Firebase
to store the data and FirebaseListObservable
to fetch my information, but I'm not able to transform FirebaseListObservable
to array
, tried to put variable requests within foreach
but when I check it it returns me undefined
.
Is there any other way to feed my smart-table
to FirebaseListObservable
?