获取数组长度

时间:2019-05-28 16:05:21

标签: angular angular-material

我需要过滤一个MatTableDataSource,它具有Workspacemodel类型的数组。

我在下面尝试了此方法,并成功获取了在html文件中输入的所有输入的工作区模型

public workspaces: MatTableDataSource<WorkspaceModel>;
ngOnInit(): void {
        this.newForm();
        this.getWorkspaces();
        this.user.name = this.employee.employeeName;
    }

public verifyIfHaveThisWorkspaceName(workspace?: string): boolean {
        if (!this.workspaces) {
            return;
        }
        workspace = workspace.trim();
        workspace = workspace.toLowerCase();
        this.workspaces.filter = workspace;
    }

public getWorkspaces() {
        this.workspacesService.getWorkspaces().subscribe(response => {
            if (response) {
                this.createWorkspacesTable(response)
            }
        }, (error) => {
            alert("Ocorreu um erro ao tentar carregar os Assuntos")
        });
    }

public createWorkspacesTable(response) {
        this.workspaces = new MatTableDataSource(response);
        this.workspaces.paginator = this.paginator;
        this.workspaces.sort = this.sort;
    }

界面就是这样

export interface WorkspaceModel {

    createdAt: Date;
    createdBy: User | null;
    db: boolean;
    description: string;
    language: string;
    learning_opt_out: boolean;
    name: string;
    updatedAt: Date;
    updatedBy: User | null;
    watson: boolean;
    _id: string;
    activated: boolean;
    master: string | null;
}

现在,我需要一个在html输入中键入后返回数组长度的方法。如何执行?我认为必须使用_filterData(),但我不知道如何使用,请帮助我。

0 个答案:

没有答案