我们有services.ts。需要两个参数
更新的似乎是我看错了错误。此方法导致控制台错误。
private checkLink(row, options) {
if (options.type ==='link' || options.type ==='custom-method') {
if (options.type === 'link' || (options.type === 'custom-method' && (row.user_id === this.userData.id) || this.authService.permission('view_subject_data') || this.userData.id === row.section.user_id || this.userData.id === 1)) {
if (options.permission) {
if (this.authService.permission(options.permission)) {
this.router.navigate([`${options.link}/${row[options.linkKey]}`]);
}
} else {
this.router.navigate([`${options.link}/${row[options.linkKey]}`]);
}
}
}
}我把它调用到我的html表,它被许多组件使用。
<span [innerHtml]="datatableService.setColumnData(row[column.prop], column.options, row)"下面是我传递给setColumnData的数据
columns = [
{
name: 'User',
prop: 'last_name',
options: {
type: 'piped',
pipes: ['displayFullName']
},
},
{
name: 'Action',
prop: 'description'
},
{
name: 'Time',
prop: 'created_at',
options: {
type: 'piped',
pipes: ['formatDateTime']
},
},
];这给了我type undefined,但是代码可以工作。我只需要消除console.log错误。

我知道我只需要像这样提供必要的论据。而且没有错误。
{
name: 'Action',
prop: 'description',
options: ''
},但问题是,我需要在整个项目中更改所有类似的columns变量。有没有更简单或干净的方法来做这件事?
发布于 2022-08-11 06:07:14
您是否尝试过调用服务&通过component.ts文件将值存储在ngAfterViewInit中,而不是直接在component.html文件中调用它,这些值是在视图呈现后启动的,因此应该抛出未定义的值,因为该值没有启动。
public tableData:yourType = []
ngAfterViewInit():void{
this.tableData = this.datatableService.setColumnData(this.row[this.column.prop], this.column.options, this.row)
} https://stackoverflow.com/questions/73315824
复制相似问题