grunt错误TS2304找不到名称

时间:2015-04-23 15:00:30

标签: angularjs gruntjs typescript definitelytyped

我在与error TS2304: Cannot find name 'ICookiesService'挣扎。尽管我搜索了解决方案,但我似乎找不到解决方案。我相信参考是正确的。我在app.ts中加载了模块ngCookies并添加了依赖项。我错过了什么?

非常感谢你的帮助......

我的控制器看起来像这样:

/// <reference path='loginComponentScope.interface.ts' />
/// <reference path='xxx/angular-cookies.d.ts' />
/// <reference path='xxx/login.service.ts' />

'use strict';
   class LoginComponentController {

    public static $inject = [
      '$scope',
      '$cookies',
      'loginRestService'
    ];

    constructor( 
      private $scope: ILoginComponentScope,
              $cookies: ICookiesService,
              service: LoginService
    ) {
        ...     
        $cookies.put('securityToken', data);
        ...

角cookies.d.ts

 /// <reference path="angular.d.ts" />
    declare module "angular-cookies" {
        var _: string;
        export = _;
    }

    declare module angular.cookies {

        interface ICookiesService {
            [index: string]: any;
        }
    ...
    }

1 个答案:

答案 0 :(得分:0)

ICookiesService在名称空间angular.cookies中声明。您需要通过该命名空间引用它(例如angular.cookies.ICookiesService),或使用import为其创建更短的本地名称(例如import ics = angular.cookies.ICookiesService,然后通过{{1}引用它})