바인딩 클래스를 입력 매개 변수로 사용하는 컨트롤러 클래스가있는 구성 요소가 있습니다. 생성자가 실행 된 후 컨트롤러의 param에 액세스 할 수 있습니다. 하지만 생성자 매개 변수로 전달할 수 없습니다.컨트롤러 클래스를 사용하여 바인딩 해결
만들기 plunker $ onInit 메서드를 사용하여 가능한 해결책을 발견했습니다. (ui-router doc).
그러나 이것은 올바른 방법입니까? 희망이 누군가에게 도움이되고 개선 될 수 있는지 말해주십시오.
class Controller {
constructor(){
'ngInject';
this.$onInit = function(){ // Comment this
this.problemScopeHere = angular.copy(this.param);
} // Comment this
console.log(this.param);
}
get(){
this.problemScopeHere = this.param;
}
}
그리고 여기 당신은 당신의 컨트롤러 클래스에 속성으로 PARAM을 추가해야합니다 구성 요소
let Component = {
bindings : {
param : "="
},
controller : Controller,
controllerAs: '$ctrl',
templateUrl: 'component.html'
};
let app = angular.module('app', ['ui.router']);
app.component('comp', Component);