[英]Datatable undefined type - Angular11
We have services.ts.我们有 services.ts。 Which needs 2 arguments
需要2个arguments
UPDATED seems like i was looking the error wrong.更新似乎我看错了。 this method was causing the console error
此方法导致控制台错误
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]}`]);
}
}
}
}
Im calling it to my html table which is used by many components.我将它称为我的 html 表,该表被许多组件使用。
<span [innerHtml]="datatableService.setColumnData(row[column.prop], column.options, row)"
Here's the data that im passing to setColumnData
这是我传递给
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']
},
},
];
Which gives me type undefined
but code works.这给了我
type undefined
但代码有效。 I just need to get rid of console.log error.我只需要摆脱 console.log 错误。
I know i just need to supply the needed arguments like this.我知道我只需要像这样提供所需的 arguments。 And it works no errors.
它没有错误。
{
name: 'Action',
prop: 'description',
options: ''
},
But the problem is i need to change all the similar columns
variable all across the project.但问题是我需要更改整个项目中所有类似的
columns
变量。 Is there anyway easier or clean way to do this?有没有更简单或更干净的方法来做到这一点?
Have you tried calling the service & storing the value in your component.ts file through ngAfterViewInit instead of calling it directly in the component.html file, The values are initiated after the view is rendered so it should throw undefined, since the value is not initiated您是否尝试过调用服务并通过 ngAfterViewInit 将值存储在您的 component.ts 文件中,而不是直接在 component.html 文件中调用它,这些值是在呈现视图后启动的,因此它应该抛出未定义的值,因为该值不是发起
public tableData:yourType = []
ngAfterViewInit():void{
this.tableData = this.datatableService.setColumnData(this.row[this.column.prop], this.column.options, this.row)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.