自定义按钮单击的 ActivatedRoute 未定义

ActivatedRoute undefined for custom button click

一旦 columnModel 可用,以下代码实例化 jqgrid 以及一个自定义按钮。这很好用。

    @Component({
       selector: 'somecomp',
       templateUrl: './somecomp.component.html'
    })
    export class SomeComponent implements OnInit{
      private _someService;
      private _route;
      constructor(someService:SomeService,route:ActivatedRoute){ 
         this._someService = someService;
         this._route = route;  
      }

      ngOnInit(){
         this.someService.getColumnModel.subscribe(columnModel=>{

            (<any>jQuery('#grid')).jqGrid({
               colModel : columnModel,
               caption : 'Data Grid',
               url : "http://sampleurl.com/data"
            });
            //custom button
            (<any>jQuery('#grid')).navButtonAdd("#pager",{
                buttonicon:"ui-icon-add",
                onClickButton : () => {
                   alert(this._route);//Route(...)
                   this._route.navigate(["/addPage"]); 
                }   
            });
...

单击此按钮后,需要导航到另一个页面,如图所示。但是,该警报未定义,并给出错误 Cannot read property 'navigate' of undefined.

如何确保this._route可用?

尝试替换:

function(){
   alert(this._route);//undefined
   this._route.navigate(["/addPage"]); 
}

与:

() => {
   alert(this._route);//undefined
   this._route.navigate(["/addPage"]); 
}

否则 this 引用作为 navButtonAdd 函数的第二个参数传递的对象