Estou tentando criar metodos para filtrar mas pelo que entendi, ele precisa ser um array, como faço pra transformar em array e ter acesso aos metodos do array?
import { DataSource } from "@angular/cdk/collections";
import { EditoriasPage } from "./../models/editorias-page";
import { Editorias } from "./../models/editorias";
import { EditoriaService } from "./../services/editoria.service";
import { Component, OnInit, ViewChild } from "@angular/core";
import { MatTableDataSource, MatSort, MatPaginator } from "@angular/material";
import { merge, Observable, of as observableOf } from "rxjs";
import { catchError, map, startWith, switchMap } from "rxjs/operators";
import { SelectionModel } from "@angular/cdk/collections";
@Component({
selector: "app-editoria-listar",
templateUrl: "./editoria-listar.component.html",
styleUrls: ["./editoria-listar.component.scss"]
})
export class EditoriaListarComponent implements OnInit {
dataSource = new EditoriaDataSource(this.editoria);
selection = new SelectionModel<EditoriaDataSource>(true, []);
//nome das colunas
displayedColumns = ["id", "name", "actions"];
public editorias: Object[] | null;
searchKey: string;
applyFilter(filterValue: string) {
//this.array.filter = this.searchKey.trim().toLowerCase();
}
onSearchClear() {
this.searchKey = "";
// this.applyFilter();
}
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
constructor(private editoria: EditoriaService) {}
ngOnInit() {
this.editoria.getAll().subscribe(_editoria => {
this.editorias = _editoria["result"];
// this.loading = false;
console.log(_editoria);
});
}
}
export class EditoriaDataSource extends DataSource<any> {
constructor(private editoria: EditoriaService) {
super();
}
connect(): Observable<Editorias[]> {
return this.editoria.getAll();
}
disconnect() {}
}
service:
import { Injectable } from "@angular/core";
import { Observable } from "rxjs";
import { HttpClient } from "@angular/common/http";
import { Editorias } from "./../models/editorias";
import { HttpUtilService } from "src/app/shared/services/http-util.service";
@Injectable({
providedIn: "root"
})
export class EditoriaService {
constructor(private _http: HttpClient, private _httpUtil: HttpUtilService) {}
getAll(): Observable<Editorias[]> {
return this._http.get<Editorias[]>(this._httpUtil.url("editorias"));
}
}