Typescript ng2可通过手机从渲染器内部访问ng组件属性

Typescript ng2可通过手机从渲染器内部访问ng组件属性,typescript,handsontable,Typescript,Handsontable,有没有办法从渲染器函数内部访问主机组件中定义的属性?我试图使用关键字“this”,但它总是未定义 import * as Handsontable from 'handsontable'; import { Component } from '@angular/core'; @Component({ moduleId: module.id, selector: "my-component", templateUrl: "my-component.component.html" })

有没有办法从渲染器函数内部访问主机组件中定义的属性?我试图使用关键字“this”,但它总是未定义

import * as Handsontable from 'handsontable';
import { Component } from '@angular/core';

@Component({
  moduleId: module.id,
  selector: "my-component",
  templateUrl: "my-component.component.html"
})
export class MyComponentComponent
  {

  public  newColumns: any[] = [{
          data: 'A',
          renderer: this.styleRenderer
        }];

 public data :any[] = [{A:'1'}]
  constructor(
  ) {
  }

  public styleRenderer(instance, td, row, col, prop, value, cellProperties) {

    Handsontable.renderers.TextRenderer.apply(this, arguments);
    console.log('is this null ?:',this);  //<-  "this" is always undefined in the given context

  }


}
import*作为“Handsontable”中的Handsontable;
从'@angular/core'导入{Component};
@组成部分({
moduleId:module.id,
选择器:“我的组件”,
templateUrl:“我的组件.组件.html”
})
导出类MyComponentComponent组件
{
public newColumns:any[]=[{
数据:“A”,
渲染器:this.styleRenderer
}];
公共数据:任意[]=[{A:'1'}]
建造师(
) {
}
公共样式呈现器(实例、td、行、列、属性、值、单元格属性){
Handsontable.renderers.textrender.apply(这是参数);
log('this null?:',this);//根据以下内容尝试

const$component=this;
public newColumns:any[]=[{
数据:“A”,
渲染器:(实例、td、行、列、属性、值、单元格属性)=>{

log('is this null?:',$component);//它通过使用箭头函数工作:

    styleRenderer = (hotTable: any, td: HTMLElement, row: any, col: any,
        prop: any, value: string, cellProperties: any) => {
        // 'this' component can be referenced from here
    }

您没有初始化数组
cellStyles:array=new array();
应该解决这个问题谢谢Aravind,但这不是问题所在,我只是编辑了问题并添加了更多信息。当您更新属性时,我可以看到完整的代码吗?谢谢Aravind,问题不在于cellStyles的值,而只是一个示例,我用它来说明我们用来重新定义的关键字this对于主机组件,访问属性的权限尚未定义,因此,我们无法访问它的属性。它只发生在styleRender函数上下文中。该函数在单独的文件中写入了什么位置?能否发布完整代码?
    styleRenderer = (hotTable: any, td: HTMLElement, row: any, col: any,
        prop: any, value: string, cellProperties: any) => {
        // 'this' component can be referenced from here
    }