Typoskript Fehler : Ein 'super' Aufruf muss die erste Anweisung in den Konstruktor, wenn eine Klasse enthält Eigenschaften initialisiert

Habe ich Folgendes Typoskript Fehler in meinem Projekt.. lass mich teilen
ein Beispiel, damit Sie sehen können, was am Umgang mit.

module CoreWeb {
export class Controller implements IController {
    public $q;
    public $rootScope;
    public $scope:ng.IScope;
    public $state:ng.ui.IStateService;
    public $translate:ng.translate.ITranslateService;
    public appEvents;
    public commonValidationsService;
    public defaultPagingOptions = {
        currentPage: 1,
        pageSize: 10,
        totalServerItems: 0,
        maxSize: 5
    };
    public detailModelName:string;
    public filter:string;
    public listModelName:string;
    public mode;
    public modelDataService;
    public modelDefaultProperty:string;
    public ngDialog;
    public notificationsService;
    public pagingOptions:IPagingOptions;
    public selectionStatus:boolean;
    public serviceCreateFunction:string;
    public serviceGetAllCanceller:ng.IDeferred<any>;
    public serviceGetAllFunction:string;
    public serviceGetOneFunction:string;
    public serviceUpdateFunction:string;
    public showInactive:boolean;
    public tableAction:number;
    public tableActions:ITableAction[];
    public titleDataFactory;
    public validationOptions;
    public validationRules;
    public orderBy = null;
    public orderType = null;
    constructor(
        $q:ng.IQService,
        $rootScope,
        $scope:ng.IScope,
        $state,
        $translate:ng.translate.ITranslateService,
        appEvents,
        commonValidationsService,
        detailModelName:string,
        listModelName:string,
        modelDataService,
        modelDefaultProperty:string,
        ngDialog,
        notificationsService,
        serviceCreateFunction:string,
        serviceGetAllFunction:string,
        serviceGetOneFunction:string,
        serviceUpdateFunction:string,
        titleDataFactory
    ) {
        this.$q = $q;
        this.$rootScope = $rootScope;
        this.$scope = $scope;
        this.$state = $state;
        this.$translate = $translate;
        this.appEvents = appEvents;
        this.commonValidationsService = commonValidationsService;
        this.detailModelName = detailModelName;
        this.listModelName = listModelName;
        this.modelDataService = modelDataService;
        this.modelDefaultProperty = modelDefaultProperty;
        this.ngDialog = ngDialog;
        this.notificationsService = notificationsService;
        this.serviceCreateFunction = serviceCreateFunction;
        this.serviceGetAllCanceller = $q.defer();
        this.serviceGetAllFunction = serviceGetAllFunction;
        this.serviceGetOneFunction = serviceGetOneFunction;
        this.serviceUpdateFunction = serviceUpdateFunction;
        this.titleDataFactory = titleDataFactory;

        this.mode = $rootScope.modeEnum.none;
        this.pagingOptions = this.defaultPagingOptions;
        this.selectionStatus = false;
        this.showInactive = false;
        this.tableAction = null;
        this.tableActions = [
            {id: 1, name: "Activate"},
            {id: 2, name: "Deactivate"}
        ];
        this.validationOptions = {showErrors: commonValidationsService.modes.property, showNotification: true};

        this.activate();
    }

Dies ist die Klasse, die erweitert die controller-Klasse.. eines unter vielen anderen

declare var App: ng.IModule;

module CoreWeb {
    export class EntityMasterController extends Controller {
        private currenciesDataSet;
        private entity: IEntityMasterModel;
        private merchandisingConstants;
        private typeAheadOptions;

    constructor(
        $q:ng.IQService,
        $rootScope,
        $scope:ng.IScope,
        $state,
        $translate:ng.translate.ITranslateService,
        appEvents,
        commonValidationsService,
        entityDataService,
        merchandisingConstants,
        ngDialog,
        notificationsService,
        titleDataFactory
    ) {
        this.merchandisingConstants = merchandisingConstants;
        super(
            $q,
            $rootScope,
            $scope,
            $state,
            $translate,
            appEvents,
            commonValidationsService,
            "entity",
            null,
            entityDataService,
            "name",
            ngDialog,
            notificationsService,
            "createEntity",
            "getCurrentEntity",
            "getEntity",
            "updateEntity",
            titleDataFactory
        );
    }

Nun, wenn ich initialisieren die merchandisingConstants vor dem super-Aufruf wie oben.. ich bekomme die folgende Fehlermeldung beim schlucken und meine Seite nichts angezeigt.. Ein super Aufruf muss die erste Anweisung in den Konstruktor, wenn eine Klasse enthält Eigenschaften initialisiert oder hat parameter-Eigenschaften. Ich habe versucht, alle Möglichkeiten, die ich denken kann ausgeschaltet, um beheben diese Fehler keine Idee, wie ich das angehen?

Nun könnte man halten, dass die Initialisierung in der super argument-Liste über einen Komma-operator oder so etwas.
Was ist das problem mit dem verschieben der this.merchandisingConstants Zuordnung unterhalb der super nennen?
Ich denke, es ist sehr deutlich aus der Fehlermeldung, die Sie brauchen nur zu bewegen, die super(.. als erste Anweisung in den Konstruktor.
wie kann ich das tun?
Machen Sie den ersten parameter zu super() werden (this.merchandisingConstants = merchandisingConstants, $q) - das wird die Wirkung haben, tun die Zuweisung vor der super() nennen, passiert, und es wird auch übergeben Sie den Wert der $q genau wie in deinem code. Stellen Sie sicher, dass Sie die Klammern so, dass die , wird interpretiert als der Komma-operator und nicht ein Komma-Trennzeichen in der Parameterliste.

InformationsquelleAutor KinyoriDeStephen | 2015-07-29

Schreibe einen Kommentar