2016-12-28 2 views
1

私は1.5の角度でTypescriptを使用しています。変数にコンポーネントをバインディングに渡す際に問題が発生しています。Typescriptの角度1.5のコンポーネントがバインディング変数文字列を渡していません

関連するコードは次のとおりです。関連していないコードの大半を取り除きました。

module xyz.dashboard { 

class PatientPhaseCountController { 

    public static $inject = []; 

    public title: string; 

    public chartType: string; 

    ///// /* @ngInject */ 
    constructor() { 
     this.title = 'Patient Phase Count'; 

     console.log(this.chartType); 
     this.$onInit(); 
    } 

    public $onInit(): void { 
     console.log(this); 
    }; 

} 

class PatientPhaseCount implements ng.IComponentOptions { 
    public bindings: any; 
    public controller: any; 
    public templateUrl: string; 

    constructor() { 
     this.bindings = { 
      chartType: '@' 
     }; 
     this.controller = PatientPhaseCountController; 
     this.templateUrl = 'app/dashboard/patientPhaseCount/patientPhaseCount.component.html'; 
    } 
} 

}

、ここでHTMLスニペットです:

ChartTypeを、常に定義されていません。どんな助けもありがとうございます。

答えて

0

私は同様の問題を抱えていました。これに対する私の解決策は、コントローラクラスに$ scopeサービスを注入することでした。 $スコープにはデフォルトで$ ctrlと呼ばれるコントローラがあり、$ ctrlにはバインディングを見つけることができます。だからあなたの場合、解決策はこのようになるでしょう

module xyz.dashboard { 
     class PatientPhaseCountController { 
     public static $inject = []; 
     public title: string; 
     public chartType: string; 
     ///// /* @ngInject */ 
     constructor(private $scope:any) { 
      this.title = 'Patient Phase Count'; 
      console.log(this.$scope.$ctrl.chartType); 
      this.$onInit(); 
     } 
     public $onInit(): void { 
      console.log(this); 
     }; 
     } 

     class PatientPhaseCount implements ng.IComponentOptions { 
     public bindings: any; 
     public controller: any; 
     public templateUrl: string; 
     constructor() { 
      this.bindings = { 
       chartType: '@' 
      }; 
      this.controller = ["$scope",($scope:any)=>{ 
       return new PatientPhaseCountController($scope); 
      }; 
      this.templateUrl = 'app/dashboard/patientPhaseCount/patientPhaseCount.component.html'; 
     } 
     } 
    } 
関連する問題