Ala*_*an2 14 javascript angularjs typescript
在我的代码中我有这个:
/// <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
) {
Run Code Online (Sandbox Code Playgroud)
有人能告诉我如何为$ http和$ q添加Typescript类型?我已经引用了AngularJS类型定义文件,但是这些类型仍然没有显示出来
PSL*_*PSL 27
如果您的项目中包含打字,您只需将其用作变量的类型,这样就可以在intellisense上显示该类型的属性/函数.
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
) {
Run Code Online (Sandbox Code Playgroud)
同样,您也可以指定服务示例的接口类型for enumService.您也可以扩展现有类型.例如,您的范围有自己的功能,然后使用范围作为您的viewModel: -
interface IquestionHomeViewModel extends ng.IScope {
func1(arg:string):void;
...
}
Run Code Online (Sandbox Code Playgroud)
你会用它作为: -
$scope : IquestionHomeViewModel ,
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9501 次 |
| 最近记录: |