gpt4 book ai didi

angular - ngx-cookieconsent : Cannot find name 'NgcInitializeEvent' and 'NgcStatusChangeEvent'

转载 作者:行者123 更新时间:2023-12-01 11:18:56 24 4
gpt4 key购买 nike

我想在我的 angular 4 应用程序(使用 angular cli 构建)中使用 ngx-cookie 同意包。我没有 systemjs 文件。因此,除了那部分之外,我按照文档中的每个步骤(https://tinesoft.github.io/ngx-cookieconsent/doc/index.html)进行了操作。
我有 4 条错误消息

  • 以下消息有两个错误
    //Cannot read property 'initialise' of undefined at 
    //NgcCookieConsentService.init (cookieconsent.service.js:53)
    //at new NgcCookieConsentService (cookieconsent.service.js:23)
    //at _createClass (core.es5.js:9532)
    //at createProviderInstance$1 (core.es5.js:9500)
    //at resolveNgModuleDep (core.es5.js:948 5)
    //at NgModuleRef.get (core.es5.js:10577)
    //at resolveDep (core.es5.js:11080)
    //at createClass (core.es5.js:10933)
    //at createDirectiveInstance (core.es5.js:10764)
    //at createViewNodes (core.es5.js:12212)
  • 找不到名称“NgcInitializeEvent”。
    找不到名称“NgcStatusChangeEvent”。

  • 请帮忙。

    最佳答案

    我是 ngx-cookieconsent 的作者.
    我已经在项目的问题跟踪器上回答了问题,但对于 future 的 googlers,它们是:

  • 找不到“NgcInitializeEvent”和“NgcStatusChangeEvent”

  • 如果要在代码中使用这些事件,则需要导入它们:
    import { NgcInitializeEvent, NgcStatusChangeEvent } from 'ngx-cookieconsent';
  • Cookie 状态未持久化

  • 您需要设置 'cookie.domain'配置对象的参数(即使在本地主机中),以便正确设置 cookie:
    import {NgcCookieConsentModule, NgcCookieConsentConfig} from 'ngx-cookieconsent';

    const cookieConfig:NgcCookieConsentConfig = {
    cookie: {
    domain: 'localhost' // or 'your.domain.com' // it is mandatory to set a domain (even in localhost), for cookies to work properly
    }
    };

    @NgModule({
    declarations: [AppComponent, ...],
    imports: [NgcCookieConsentModule.forRoot(cookieConfig), ...],
    bootstrap: [AppComponent]
    })
    export class AppModule {
    }

    注:如果您在消费应用程序中使用 Angular CLI,您可以利用 environments根据您的运行环境控制域:

    环境/environment.ts: (开发)
    export const environment = {
    production: false,
    cookieDomain: 'localhost' // -<< must be 'localhost'
    };

    环境/environment.prod.ts: (产品)
    export const environment = {
    production: true,
    cookieDomain: 'your.domain.com' // -<< must be the domain of deployed app
    };

    并使用它:
    import {NgcCookieConsentModule, NgcCookieConsentConfig} from 'ngx-cookieconsent';
    import { environment } from './../environments/environment';

    const cookieConfig:NgcCookieConsentConfig = {
    cookie: {
    domain: environment.cookieDomain // -<< domain will change base on your running env
    }
    };

    @NgModule({
    declarations: [AppComponent, ...],
    imports: [NgcCookieConsentModule.forRoot(cookieConfig), ...],
    bootstrap: [AppComponent]
    })
    export class AppModule {
    }

    关于angular - ngx-cookieconsent : Cannot find name 'NgcInitializeEvent' and 'NgcStatusChangeEvent' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46583242/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com