Reputation: 1746
I have installed Angular TypeScript defintion typing (VS2015). The typings seem to work mostly including "ng-" directives within the HTML or "angular." will work BUT when i try to use intellisense on an injected variable such as $scope... no luck and the intellisense does not show up.
Is this a limit of the DefinitelyTyped https://github.com/borisyankov/DefinitelyTyped library or should it be working?
Upvotes: 0
Views: 97
Reputation: 28686
It can't work out of box because you can add anything to your $scope
object.
I think there are two ways to make compiler happy. The first way requires less typing:
function Controller($scope: ng.IScope) {
$scope.$broadcast('myEvent');
$scope['title'] = 'Yabadabadu';
}
and the second way is:
interface IMyScope extends ng.IScope {
title: string;
}
function Controller($scope: IMyScope) {
$scope.$broadcast('myEvent');
$scope.title = 'Yabadabadu';
}
I use the first approach for simple directives and the second for more complex ones.
Upvotes: 0
Reputation: 1746
I annotated $scope with the interface ng.IScope. The compiler now knows $scope has methods
function Controller($scope: ng.IScope) {
$scope.$broadcast('myEvent');
$scope.title = 'Yabadabadu';
}
Upvotes: 1