【问题标题】:How to call angular service from SlickGrid custom editor如何从 SlickGrid 自定义编辑器调用角度服务
【发布时间】:2017-08-24 19:00:09
【问题描述】:

如何从 slickgrid 自定义单元格编辑器调用角度服务。 下面提到了描述 slickgrid 自定义单元格编辑器的链接。

https://github.com/mleibman/SlickGrid/wiki/Writing-custom-cell-editors

function IEditor(args) {
    this.applyValue = function(item,state) {

    // Unable to get the service in the editor context.
    // this.testService is undefined.
    this.testService.getDetails(itemId).get(result =>{
       console.log(result );
    });
  };        
}

在编辑器上下文中获取服务时遇到问题。我尝试了 this 和 self 但没有成功。

【问题讨论】:

标签: angularjs slickgrid


【解决方案1】:

第二个 .this 与包装函数的上下文不同。你应该这样写:

 function IEditor(args) {

  var that = this;
  this.applyValue = function(item,state) {

  // Unable to get the service in the editor context.
  // this.testService is undefined.
  that.testService.getDetails(itemId).get(result =>{
     console.log(result );
  });
 };        
}

或者如果你使用的是 ES6:

 function IEditor(args) {

  this.applyValue = (item,state) => {

  // Unable to get the service in the editor context.
  // this.testService is undefined.
  this.testService.getDetails(itemId).get(result =>{
     console.log(result );
  });
 };        
}

【讨论】:

  • 感谢您的回答,但在我的情况下它不起作用,因为时间这个和那个只有编辑器上下文。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-20
  • 1970-01-01
  • 2017-05-18
相关资源
最近更新 更多