Wie kommt es, dass ich keinen Bereich für $scope
außerhalb des Konstruktors habe, es sei denn, ich definiere meine Funktion mit dem Fettpfeil? Oder ist es möglich, auf $ scope zuzugreifen, ohne eine Funktion mit dem Fettpfeil zu definieren?
namespace FooBar {
export interface MyScope extends ng.IScope {
message: string;
}
export class SandboxCtrl {
static $inject = ["$scope", "$timeout"];
private scope: MyScope;
private timeout: ITimeoutService;
constructor($scope: MyScope, $timeout: ng.ITimeoutService) {
this.scope = $scope;
this.timeout = $timeout;
timeout(this.foo, 1000); // does not work
timeout(this.bar, 1000); // works
}
public foo() {
this.scope.message = "foo bar"; // does not work
}
bar =() => {
this.scope.message = "foo bar"; // works
}
}
}
UPDATE ich bemerkte ich nicht das ganze Problem geteilt habe, wie ich es, weil $timeout
Richtlinie nicht wusste, tat, war, die das Problem verursacht. Jedenfalls habe ich mein Beispiel aktualisiert.
haben Sie DefinitelyTyped angualer Dateien Sie Projekt hinzufügen? – NinjaDeveloper
@NinjaDeveloper ja, ich habe. – starcorn