2016-04-05 4 views
0

私のES6コントローラクラスは以下の通りです。私は$ compileのようなAngularメソッドを実行することができません。$ locationは、コードの約束を解決します。 "Uncaught(約束事)TypeError:this。$ compileは関数ではありません(...)"私はこのアクセスを約束の中で得るために矢印関数を使用しています。どのようにこれを解決するためのアイデア?

import DashboardService from './DashboardService'; 

class DashboardController 
{ 
    /*@ngInject*/ 
    constructor($scope, DashboardService, $location, $compile, PLATFORM) 
    { 
     this.$scope = $scope; 
     this.DashboardService = DashboardService; 
     this.$location = $location; 
     this.$compile = $compile; 
     this.PLATFORM = PLATFORM; 
    } 

    UpdateGrid(clients) 
    { 
     this.PLATFORM.miraLoader.moduleImport('platform!kendo-ui').then((kendo) => {   
      var dataSource = new kendo.data.DataSource({ data: clients, pageSize: 10 }); 
      angular.element("#GridTest").kendoGrid({ 
       height: 415, 
       scrollable: true, 
       dataBound: function(){this.$compile(angular.element("#GridTest"))(this.$scope);} 
      }); 
      var grid = angular.element("#GridTest").data("kendoGrid"); 
      grid.setDataSource(dataSource); 
      grid.dataSource.read(); 
      this.$compile(angular.element("#GridTest"))(this.$scope); 
     }); 
    } 

    GoToClient(id){ this.$location.path('/Client/'+id); } 

    AdvisorChange() { 
     this.DashboardService.ClientsGet(this.wiquid, this.advisorid).then((clients) => { 
      this.UpdateGrid(clients.data.d); 
     }); 
    } 
} 
export default DashboardController; 

答えて

0

矢印演算子を使用すると、thenのために、成功コールバック内this.$compile()にアクセスすることができますが保証はできますが、別のコールバックdataBound内部からアクセスしようとしています。

次のいずれかを実行できます。 UpdateGrid中:コールバックコールvm.$compile(...)で、その後

const vm=this 

または使用:

dataBound: (function(){this.$compile(angular.element("#GridTest"))(this.$scope);}).bind(this) 

dataBoundコールバック内部の期待値を持つようにthisを強制します。

それとも、置くことができる:UpdateGrid

const $compile = this.$compile 

とだけコールバックから$compile(...)を呼び出します。

+0

おかげでダンカン..今はうまくいきます... –

関連する問題