2015-05-05 5 views
6

Wie der Titel ich folgende TSLint Fehler erhalten deklariert werden:

'$http' cannot be declared in the constructor

ich nichts im Zusammenhang mit diesem Fehler im Internet finden konnte.

Hier ist mein Code:

module MyModule { 
    "use strict"; 

    class MyService { 
     static $inject = ["$http"]; 
     constructor(private $http: ng.IHttpService) { 
     } 
    } 
} 

Antwort

10

So wie ich die Frage gestellt wurde mir klar, ich brauche meine tslint.json-Datei zu überprüfen, und ich fand dies:

"no-constructor-vars": true, 

Offenbar dies auf tslint's github page dokumentiert ist:

no-constructor-vars disallows the public and private modifiers for constructor parameters.

Also ist die Lösung einfach zu deaktivieren no-constructor-vars:

"no-constructor-vars": false, 
+0

'no-Konstruktor-vars' hat' no-Parameter-properties' umbenannt, siehe https://github.com/palantir/tslint/issues/1296 – Bob

Verwandte Themen