2016-10-31 10 views
0

es6angular 1.5ui.gridで使用しています。グリッドAPIにafterCellEditイベントを登録しているうちに、$scopeの代わりに何を渡す必要がありますか?gridApi.edit.on.afterCellEdit(ES6を使用)

export default class MyController{ 
// other codes skipped 
registerGrdApi(gridApi) { 
     this.grdApi = gridApi; 
     gridApi.edit.on.afterCellEdit(this, this.afterCellEdit); 
} 

afterCellEdit(rowEntity, colDef, newVal, oldVal){ 
    // this.window.console.log(oldVal+" is changed to "+newVal); 
} 
} 

我々は通常thisMyControllerとしてクラスを渡す現在のスコープですが、私はエラーの下に受け付けております。

asked to listen on edit.on.afterCellEdit but scope wasn't passed in the input parameters. It is legitimate to pass null, but you've passed something else, so you probably forgot to provide scope rather than did it deliberately, not registering 

gridApi.edit.on.afterCellEdit(null, this.afterCellEdit); 

下に述べたように、私はnullを使用するときに、私は、グリッド上で、いくつかの編集を実行するたびに、それは誤り下に示します上記のエラーメッセージでsuggesstedとして、私はここで何をしないのですか?

TypeError: Cannot read property 'apply' of undefined 
+0

関数スコープを必要とする場合、スコープを渡します。私は何が問題なのか分かりません。 _ "私たちは通常、MyControllerクラスが現在のスコープであるため、これを渡します" _いいえ、スコープではありません。 – zeroflagL

答えて

0

MyControllerを注入しながら$scopeを渡すときに解決の問題。後でonRegisterApiの変数を使用します。以下は動作するコードです。

`

export default class MyController{ 
// constructor 
MyController($scope){ 
    this.scope = $scope; 
    this.gridOptions = { 
    columnDefs: this.colDefs, 
    data: this.gridData, 
    enableFiltering: true, 
    appScopeProvider: this, 
    onRegisterApi: this.registerGrdApi, 
    }; 
} 
// other codes skipped 
registerGrdApi(gridApi) { 
    this.grdApi = gridApi; 
    var _self = this.appScopeProvider; 
    gridApi.edit.on.afterCellEdit(_self.scope, _self.afterCellEdit); 
} 
afterCellEdit(rowEntity, colDef, newVal, oldVal){ 
    // this.window.console.log(oldVal+" is changed to "+newVal); 
} 
} 
MyController.$inject = ['$scope']; 

`

関連する問題