简体   繁体   中英

grunt error TS2304 cannot find name

I'm struggling with error TS2304: Cannot find name 'ICookiesService' . Despite I searched for solutions I don't seem to find one. I believe the reference is correct. I loaded the module ngCookies in app.ts and added the dependency. What am I missing?

Many thanks for your help...

My controller looks like this:

/// <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);
        ...

angular-cookies.d.ts

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

    declare module angular.cookies {

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

ICookiesService is declared in the namespace angular.cookies . You need to reference it via that namespace (eg angular.cookies.ICookiesService ), or use an import to create a shorter local name for it (eg import ics = angular.cookies.ICookiesService , then refer to it by ics )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM