use*_*730 4 cookies banner angular-cli angular
我想在我的 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)
Run Code Online (Sandbox Code Playgroud)
请帮忙。
我是ngx-cookieconsent的作者。我已经在项目的问题跟踪器上回答了问题,但对于未来的 googlers,它们是:
如果要在代码中使用这些事件,则需要导入它们:
import { NgcInitializeEvent, NgcStatusChangeEvent } from 'ngx-cookieconsent';
Run Code Online (Sandbox Code Playgroud)
您需要设置'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 {
}
Run Code Online (Sandbox Code Playgroud)
注意:如果您为消费应用程序使用 Angular CLI,您可以利用环境来根据您的运行环境控制域:
环境/environment.ts:(开发)
export const environment = {
production: false,
cookieDomain: 'localhost' // -<< must be 'localhost'
};
Run Code Online (Sandbox Code Playgroud)
环境/environment.prod.ts : (prod)
export const environment = {
production: true,
cookieDomain: 'your.domain.com' // -<< must be the domain of deployed app
};
Run Code Online (Sandbox Code Playgroud)
并使用它:
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 {
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2753 次 |
| 最近记录: |