我的app.component.html
是:
<app-data-table [data]="data" [tableInfo]="productOrderInfo" (modified)="onModification($event)">
</app-data-table>
我的data-table.html
完全为空,但仍然显示该obj符号。
我的data.table.component.ts
(我认为这无关紧要,但确实如此):
import { Component, OnInit, Input, ViewChildren, QueryList, ViewChild, Output, EventEmitter, ElementRef, AfterViewInit, ComponentRef } from '@angular/core'; import { EditableValueComponent } from '../editable-value/editable-value.component'; import { ColumnInfo, TableInfo } from '../editable-value/editable-type'; import { MatTableDataSource, MatTable, MatSort, MatPaginator, MatDialog } from '@angular/material'; import { SelectionModel } from '@angular/cdk/collections'; import * as Lodash from 'lodash'; import { EditableOpenObjectComponent } from '../editable-value/editable-object/editable-open-object/editable-open-object.component';
export class TableInsert { constructor(public rows: object) { } }
export class TableDelete { constructor(public rows: object[]) { } }
export class TableUpdate { constructor(public row: object, public column: string, public value: any) { } }
export class TableFeatures { sort?: boolean; filter?: boolean; edit?: Array<string> | boolean; select?: boolean; insert?: boolean; delete?: boolean; save?: boolean; close?: boolean; header?: boolean; pagination?: boolean; }
@Component({ selector: 'app-data-table', templateUrl: './data-table.component.html', styleUrls: ['./data-table.component.scss'] }) export class DataTableComponent implements OnInit { @ViewChildren('editableValue') editableValues: QueryList<any>; @ViewChild(MatTable, { static: true }) table: MatTable<any>; @ViewChild(MatSort, { static: true }) sort: MatSort; @ViewChild(MatPaginator, { static: false }) paginator: MatPaginator;
@Input() tableInfo: TableInfo; @Output() modified = new EventEmitter<TableUpdate | TableInsert | TableDelete>(); @Output() save = new EventEmitter<object[]>(); @Output() cancel = new EventEmitter<object[]>();
defaultFeatures: TableFeatures; dataSource = new MatTableDataSource<any>([]); selection = new SelectionModel<any>(true, []);
constructor(public dialog: MatDialog) {
this.defaultFeatures = {
sort: true,
filter: true,
pagination: true,
edit: true,
select: true,
insert: true,
delete: true,
close: false,
save: false,
header: true,
}; }
@Input() set data(data: object[] | Promise<object[]>) {
// data = Promise.resolve(data);
// data.then(data2 => {
// this.dataSource.data = data2 === undefined ? [] : data2
// }); }
get data() {
return this.dataSource.data; }
ngOnInit() {
console.log(this.dataSource.data);
this.dataSource.sort = this.sort;
setTimeout(() => this.dataSource.paginator = this.paginator, 0);
this.tableInfo.features = Object.assign({}, this.defaultFeatures, this.tableInfo.features); }
onSave() {
this.save.emit(this.data as object[]); }
onCellClick(editableValue: EditableValueComponent, column: string) {
if (
this.openedEditableValue === undefined &&
this.tableInfo.features.edit !== false &&
(this.tableInfo.features.edit === true || (this.tableInfo.features.edit as any).indexOf(column) > -1)
) {
editableValue.open = true;
} }
onUpdate(row: object, column: string, value: any) {
const update = new TableUpdate(Lodash.clone(row), column, value);
row[column] = value;
this.modified.emit(update); }
onInsert() {
const dialogRef = this.dialog.open(EditableOpenObjectComponent, {
width: '320px',
data: { value: {}, typeInfo: this.tableInfo.columnInfo, title: 'Insert' },
autoFocus: false,
});
dialogRef.afterClosed().subscribe(result => {
if (result !== undefined) {
this.dataSource.data.unshift(result);
this.modified.emit(new TableInsert(result));
}
this.dataSource.data = this.dataSource.data;
}); }
onDelete() {
this.selection.selected.forEach((selected: object) => {
this.dataSource.data.splice(this.dataSource.data.indexOf(selected), 1);
});
this.modified.emit(new TableDelete(this.selection.selected));
this.selection.clear();
this.dataSource.data = this.dataSource.data; }
onModification(row: object, column: string, modification: any) {
this.modified.emit(new TableUpdate(row, column, modification)); }
isAllSelected() {
const numSelected = this.selection.selected.length;
const numRows = this.dataSource.data.length;
return numSelected === numRows; }
masterToggle() {
this.isAllSelected() ?
this.selection.clear() :
this.dataSource.data.forEach(row => this.selection.select(row)); }
get columnsWithSelect() {
const columns = this.tableInfo.columnInfo.map(columnInfo => columnInfo.name);
if (this.tableInfo.features.select) {
columns.unshift('select');
}
return ['name']; }
get openedEditableValue(): any {
let editableValue2: any;
this.editableValues.forEach(editableValue => {
if (editableValue.open === true) {
editableValue2 = editableValue;
}
});
return editableValue2; }
getDataSource() {
console.log('abc');
return new MatTableDataSource([]); }
}
由于我的data-table.component.html完全为空,所以我不明白该符号怎么出现。如果我将某些内容添加到html文件中,则会显示它,并且还会显示obj徽标。