【发布时间】:2017-09-08 11:47:37
【问题描述】:
我有一个带有控制器类的组件,它使用绑定对象作为输入参数。构造函数运行后,我可以访问控制器中的参数。但我不能将它作为构造函数参数传递。
制作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;
}
}
这里是组件
let Component = {
bindings : {
param : "="
},
controller : Controller,
controllerAs: '$ctrl',
templateUrl: 'component.html'
};
let app = angular.module('app', ['ui.router']);
app.component('comp', Component);
【问题讨论】:
标签: angularjs angular-ui-router