- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将 Angular 的 Material 表集成到一个新项目中,但由于某种原因,数据没有显示,只显示空行。我在另一个项目中使用了相同的逻辑,并且它有效,我花了很多时间寻找原因但没有任何效果。
我需要将表添加到名为“cores”的延迟加载模块中,并导入 Material 表模块:
import { MatTableModule } from '@angular/material';
imports: [
CommonModule,
CoresRoutingModule,
MatTableModule
]
我创建了一个返回“ICore”对象数组的服务:
getCores(): Observable<ICore[]> {
return this.http.get<ICore[]>('/cores');
}
ICore界面:
export interface ICore {
id: number;
name: string;
}
我的“index.component.html”文件中的 HTML:
<mat-table [dataSource]="dataSource">
<ng-container matColumnDef="id">
<mat-header-cell *matHeaderCellDef> Id </mat-header-cell>
<mat-cell *matCellDef="let core"> {{ core.id }}</mat-cell>
</ng-container>
<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef> Name </mat-header-cell>
<mat-cell *matCellDef="let core"> {{ core.name }}</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>
“index.components.ts”文件中的逻辑:
dataSource = new MatTableDataSource<ICore>();
columnsToDisplay = ['id', 'name'];
constructor(private coreService: CoreService) { }
ngOnInit() {
this.coreService.getCores().subscribe(
res => {
this.dataSource.data = res;
console.log(this.dataSource);
},
err => console.log(err)
);
}
从我的 console.log 中我看到数据源已填充:
MatTableDataSource {_renderData: BehaviorSubject, _filter: BehaviorSubject, _internalPageChanges: Subject, _renderChangesSubscription: Subscriber, sortingDataAccessor: ƒ, …}
data: Array(3)
0: {id: 1, name: "core1"}
1: {id: 2, name: "core2"}
2: {id: 3, name: "core3"}
我也尝试过这个方法:
dataSource = new CoreDataSource(this.coreService);
columnsToDisplay = ['id', 'name'];
constructor(private coreService: CoreService) { }
export class CoreDataSource extends DataSource<any> {
constructor(private coreService: CoreService) {
super();
}
connect(): Observable<ICore[]> {
console.log(this.coreService.getCores());
return this.coreService.getCores(); }
disconnect() {} }
但是结果是一样的。我觉得这是一件愚蠢的事情,我忘记了做,但我没有找到它。
提前致谢!
最佳答案
确保使用相同的变量来显示您在组件中定义的列。
组件:
columnsToDisplay = ['id', 'name'];
模板:
<mat-header-row *matHeaderRowDef="columnsToDisplay"></mat-header-row>
<mat-row *matRowDef="let row; columns: columnsToDisplay;"></mat-row>
关于显示空行的 Angular Material 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56000913/
我想用 python 读取串行端口,并用 readline 打印结果,但我在所有结果行之间得到空行。你能告诉我如何删除所有空行吗? 我的代码: #!/usr/bin/python import ser
我正在编写一个程序,该程序存储用户输入的数字,但如果输入空白则退出。 我尝试将其设为字符数组并检查长度。如果长度大于0,则表示有输入,因此它将存储输入。如果长度为0,则表示没有输入,因此退出循环。 d
这个项目要求我通过取出所有注释、空行、额外的空格和括号中的信息来读取处理中的文件,然后将其打印到output.txt中。我在处理数据和删除所有注释、空行、额外的空格和括号中的信息时遇到了麻烦。 这是我
有没有办法从服务器响应中删除空行?我已经尝试过: trimSpaces true 和 这没有正确解决问题,因为在 init param 方法中它甚至删除了
你好, if('\t' == input [0] ||'\v' == input [0] ||'\r' == input [0] ||'\n' == input [0] || '\0' == in
我不知道如何用语言来解释这个场景。所以我在写例子: 我有一个名为 tblType 的表: type_id | type_name --------------------- 1 |
代码如下: <?php /* *读取文件内容至字符串中,同时去除换行、行首行尾空格。 */ header("Content-type: text/html; chars
我正在将行与两个文本文件的行进行比较,ref.txt (引用)和 log.txt .但是我想忽略任一文件中的任意数量的空行;我怎样才能做到这一点? ref.txt one two three end
关于删除jtable中未使用的行的问题我正在使用DefualtTableModel我的表已经有一些数据并且当我更新它时将一些列留空以稍后更新主题,以便它们是空列..我想在保存数据之前用按钮删除主题..
我看到列表,它有适量的行(根据 QStringList 中的元素数量),但行是空的。 我做错了什么? 在 C++ 中我的代码是: QStringList s; s.append("1"); s.app
我怎样才能从这些行中隐藏 UITableView 的行,什么是不使用的。例如,看截图: 我可以只显示 4 行并隐藏其他未使用的行吗?所以,我只显示 4 行,然后是白屏,而不是现在的行 最佳答案 喜欢将
对于我的 bash/html 中的 CGI,我有这个脚本(只是 awk 脚本,其余代码只是一个简单的 hmtl 代码): for fn in /var/www/cgi-bin/LPAR_MAP/*;
一直在尝试使用输出 html 方法转换 xml 文档,以便使用 xsl 样式表(使用 CSS)在浏览器中显示。想显示以下代码 Source A Co
我想在我的 LOG 语句之后添加一个空行,以使我的日志更加分隔和可读。 我该怎么做? 当前声明: LOGGER.info("Person's name is {} .", person.getNa
我正在执行以下假脱机语句: SET VERIFY OFF SET FEEDBACK OFF SET HEADING OFF SET TRIMSPOOL ON SET TERM OFF SPOOL &p
包含五个相关字段的表格; ID (Autoincrement,unique, etc) ID_customer - ties in each row to another table with cus
我有这样的风格: #cytoscape-container { width: 100%; height: 100%; margin: 0 aut
while((fscanf(datafile, " %127[^;] %[^\n]", name, movie)) == 2) { printf("%s\n", movi
我有这个two commands获取 SID 用户帐户 wmic useraccount where name='%username%' get sid | findstr /b /C:"S-1" >
我使用这段代码: window.removeDuplicateLines = function() { "use strict"; var bodyText = $('#text-area')
我是一名优秀的程序员,十分优秀!