在我的构造函数中,我通过:
constructor($compile, uiCalendarConfig) {
'ngInject';
this.$compile = $compile;
this.uiCalendarConfig = uiCalendarConfig;
}
当我在 $onInit() 开头记录它的值时
$onInit() {
console.log('this.$compile:', this.$compile, 'this.uiCalendarConfig:', this.uiCalendarConfig);
...
}
我得到 $compile 函数的文字代码。
但是当从内部调用 $compile
eventRender( event, element, view ) {
element.attr({'tooltip': event.title,
'tooltip-append-to-body': true});
console.log('event:', event);
console.log('edited element:', element);
console.log('view:', view);
console.log('this.$compile:', this.$compile);
this.$compile(element)(this);
};
里面提到:
this.uiConfig = {
calendar: {
height: 450,
editable: true,
header:{
left: 'title',
center: '',
right: 'today, prev, next'
},
eventClick: this.alertOnEventClick,
eventDrop: this.alertOnDrop,
eventResize: this.alertOnResize,
eventRender: this.eventRender
}
};
结果console.log('this.$compile:', this.$compile);
是undefined
this.$compile 的值。
这就是我的问题,因为我不知道为什么它在那里没有定义,如果在控制器的初始化它已经是一个函数。
有人知道我可能会错过什么吗?