在我的代码中我有这个:
/// <reference path="../../../../scripts/typings/angularjs/angular.d.ts" />
angular.module('question')
.controller('QuestionHomeController', [
'$http',
'enumService',
'$q',
'$rootScope',
'$scope',
'$state',
questionHomeController]);
function questionHomeController(
$http,
enumService,
$q,
$rootScope,
$scope,
$state
) {
有人可以告诉我如何为$ http和$ q添加Typescript类型?我已经引用了AngularJS类型定义文件,但是这些类型仍未显示
答案 0 :(得分:26)
如果您的项目中包含打字,您只需将其用作变量的类型,这样就可以在智能感知上显示该类型的属性/函数。
angular.module('question')
.controller('QuestionHomeController', [
'$http',
'enumService',
'$q',
'$rootScope',
'$scope',
'$state',
questionHomeController]);
function questionHomeController(
$http : ng.IHttpService,
enumService,
$q: ng.IQService,
$rootScope : ng.IRootScopeService,
$scope : ng.IScope,
$state : ng.ui.IStateService
) {
同样,您也可以指定服务示例for enumService
的接口类型。您也可以扩展现有类型。例如,您的范围有自己的功能,然后使用范围作为您的viewModel: -
interface IquestionHomeViewModel extends ng.IScope {
func1(arg:string):void;
...
}
你会用它作为: -
$scope : IquestionHomeViewModel ,