Question

Je viens de changer pour utiliser dossier et je reçois une erreur dès que je démarre ma demande.

Voici la façon dont je définis mon appcontroller:

app.controller('appController', AppController);

class AppController { 
    static $inject = [
        '$scope',
        '$state',
        'authService',
        'stateService',
        'userService'
    ]   
    constructor(
        public $scope: IAppControllerScope,
        ) {

        $scope.app = this;
    }  
} 

J'ai vérifié et le fichier a été chargé.

Cependant, je reçois un message indiquant:

Argument 'appController' is not a function, got undefined

Est-ce que je déclare le contrôleur correctement?Quelqu'un peut-il aider à suggérer comment je pourrais déboguer ce problème?

Était-ce utile?

La solution

Cela devrait fonctionner:

interface IAppControllerScope extends ng.IScope
{
    app : AppController;
}
class AppController { 
    static $inject = [
        '$scope',
        '$state',
        'authService',
        'stateService',
        'userService'
    ];
    constructor(public $scope: IAppControllerScope
        , public $state: any
        , public authService: any
        , public stateService: any
        , public userService: any
        ) {

            $scope.app = this;
        }  
}

var app = angular.module('myModule');

app.controller('appController', AppController);

Autres conseils

alaways d'abord déclarer les classes / modules puis le filer avec angulaire.Donc, cela fonctionnera:

class AppController { 
    static $inject = [
        '$scope',
        '$state',
        'authService',
        'stateService',
        'userService'
    ]   
    constructor(
        public $scope: IAppControllerScope,
        ) {

        $scope.app = this;
    }  
} 

app.controller('appController', AppController);

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top