我想在我的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)
请帮忙。
答案 0 :(得分:4)
我是ngx-cookieconsent的作者。 我已经回答了关于项目问题跟踪器的问题,但对于未来的googlers,他们在这里:
如果要在代码中使用这些事件,则需要导入它们:
import { NgcInitializeEvent, NgcStatusChangeEvent } from 'ngx-cookieconsent';
您需要设置配置对象的'cookie.domain'
参数(即使在localhost中),以便正确设置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 / environment.ts:(dev)
export const environment = {
production: false,
cookieDomain: 'localhost' // -<< must be 'localhost'
};
environments / environment.prod.ts:(prod)
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 {
}
答案 1 :(得分:0)
我有同样的问题。通过将min.js
和min.css
添加到angular.json
文件中来解决。
参见:https://github.com/tinesoft/ngx-cookieconsent