我正在开发ng2智能表,我希望将一行(甚至单元数据)更改为链接(routerlink),我目前正在使用此方法来获取该行的一些数据:
onUserRowSelect(event)
{
console.log('user row select: ', event);
this.selected = event.selected;
console.log('selected list: ', this.selected);
this.router.navigate(["/dashboard"]);
console.log("this is a test ");
}当然,事件来自HTML,我使用this.router.navigate导航到另一个页面,问题是总是会发生错误,告诉我
1215/SmartTables.prototype.onUserRowSelect@http: TypeError: this.router是未定义的堆栈跟踪:this.router
有人能告诉我1)这里的问题是什么,2)如何从事件中提取数据(它正在返回一个Object)。非常感谢
发布于 2019-05-30 09:34:07
在您的设置中,在列中配置如下
objektelinks: {
title: 'Objektelink',
type: 'custom',
renderComponent: LinkViewComponent,
},创建这样的呈现组件
import { Component, OnInit, Input, Output, EventEmitter } from
'@angular/core';
import { ViewCell } from 'ng2-smart-table';
@component({
selector: 'ngx-link-view',
template: <a [routerLink]= "['/auth/register']"> Objekte </a>,
})
export class LinkViewComponent implements ViewCell, OnInit {
renderValue: string;
@input() value: string | number;
@input() rowData: any;
@output() save: EventEmitter = new EventEmitter();
ngOnInit() {
enter code here
}
}发布于 2017-05-12 12:08:57
我现在也在为类似的问题而战,但是..。这可能对你有帮助:
- Have you imported Router from '@angular/core'? If not: _import { Router /_ ... _/ } from "@angular/router";_
- Have passed to constructor Router object? If not do something like this: _constructor(private_ _**router:Router**__) {/_ ... _/}_
我希望我能帮上忙。
https://stackoverflow.com/questions/43936274
复制相似问题