1
저는 Typescript를 사용하여 AngularJs에 응용 프로그램을 작성하고 있으며 컨트롤러 클래스의 지시문에있는 메서드에 액세스하는 데 문제가 있습니다. '제어'내가 추가 컨트롤러에 지시의 방법의 컨트롤을 바인딩 할이 생각이 지침의 범위에, '=하지만 오류를 얻고있다컨트롤러의 지시문 메서드에 액세스하십시오.
컨트롤러 코드는 다음과 같습니다
import {DaypartingSegmentsContainer} from "lib/js/publisher/deal/objects/dayparting/dayparting.segments.container";
@Component({
bindings: {
deal: "="
},
controllerAs: "$ctrl",
module: DealApp,
require: {
DealForm: '^form',
},
selector: 'deal-edit-dayparting',
template: require('./templates/deal.edit.dayparting.html'),
})
@Inject(
"$scope",
"$q"
)
export class DealEditDaypartingCtrl extends SxControllerBase {
public daypartingSegmentsContainer : DaypartingSegmentsContainer;
constructor(protected $scope : ng.IScope,
private $q : angular.IQService) {
super($scope);
}
public $onInit() : void {
let self : DealEditDaypartingCtrl = this;
this.daypartingSegmentsContainer.getCommonTimes();
}
}
이 지침 클래스는 다음과 같습니다
import {Inject, Directive} from "lib/js/angularjs/decorators/sx-forward";
import DealApp from "lib/js/publisher/deal/lib.deal.app";
import DealEditDaypartingCtrl from "lib/js/publisher/deal/edit/deal.edit.dayparting";
import "lib/js/publisher/deal/objects/dayparting/dayparting.jquery.factory";
import {DaypartingDayName} from "lib/js/publisher/deal/objects/dayparting/dayparting.day.name";
import {
minutesToString,
stringToMinutes
} from "lib/js/publisher/deal/objects/dayparting/dayparting.time.functions";
@Directive({
selector: 'dayparting-segments-container',
require: '^dealEditDayparting',
replace: true,
module: DealApp,
scope: {
dayName: '<',
control: '=',
},
template: require('./templates/dayparting.segments.container.html'),
controllerAs: '$ctrl',
link: function(scope : any, element : any, attrs : any, daypartingCtrl : DealEditDaypartingCtrl) : void {
scope.daypartingCtrl = daypartingCtrl;
// Delete button watch
scope.$watch(
() => {
return daypartingCtrl.deleteSegment;
},
(shouldDelete : boolean) => {
if (shouldDelete === true) {
scope.$ctrl.onDelete();
}
}
);
// Calendar leave watch
scope.$watch(
() => {
return daypartingCtrl.calendarLeave;
},
(calendarLeave : boolean) => {
if (calendarLeave === true) {
scope.$ctrl.onCalendarMouseLeave();
}
}
);
},
})
@Inject('$scope', 'JQueryFactory')
export class DaypartingSegmentsContainer {
constructor(private $scope : any,
private JQueryFactory : any) {
this.tooltipIsOpen = false;
this.jquery = JQueryFactory.get();
}
public getCommonTimes() : void {
console.log("i am in getCommon times!!!")
}
}
export default DaypartingSegmentsContainer;
Cannot read property 'getCommonTimes' of undefined