2
我有一个带有JS功能的TypeScript组件。该功能由Kendo UI调用,因此该功能在Javascript上下文中执行,这意味着我不能使用“this”(这将返回调用者Kendo组件)。我想在这个函数中重定向页面,但我宁愿使用router.navigate *函数而不是location.href替换。是否有可能在Javascript上下文中访问路由器实例?使用Javascript代码访问路由器
export class MyComponent implements AfterViewInit {
//template: `<div #grid></div>`
@ViewChild('grid') private grid: ElementRef;
ngAfterViewInit() {
this.configureGrid();
}
private configureGrid() {
let kendoGrid: kendo.ui.Grid = jQuery(this.grid.nativeElement).data("kendoGrid");
let kendoColumn: kendo.ui.GridColumn = {};
kendoColumn.command = { text: "My Button", click: this.myButtonCommand, className: "btn" };
kendoGrid.columns.add(kendoColumn);
}
myButtonCommand(e) {
//redirect here
}
}
请出示一些代码。 –
你可以使用'var that = this;'trick。 https://www.google.com/?gfe_rd=cr&ei=20AjV9HqFMaFzAW_grrgCg&gws_rd=ssl#q=javascript+this+that –
您是否尝试过{{text:“我的按钮”,点击:this.myButtonCommand.bind(this), className:“btn”};'? –