如何以编程方式 open/close ngx cookie 同意弹出窗口?

How can I programmatically open/close ngx cookie consent popup?

我正在使用 ngx-cookie-consent 和 Angular。 我想找到一种以编程方式 display/hide 弹出窗口

的方法

我尝试通过 NgcCookieConsentService 的实例访问方法 close 但没有成功

我们的想法是 link 这样:

html:

<div>
    <span (click)="displayPopPup()"> display pop up</span>
</div>

.ts

displayPopup = () => {
    //trigger the popup display 
}

在您的构造函数中,您可以声明 NgcCookieConsentService 的实例 class:

private ccService: NgcCookieConsentService

然后在你的函数中你可以调用open函数来重新打开cookie弹出窗口。

this.ccService.open();

我发现的方法是从 NgcCookieConsentService 实例调用函数 fadeIn()fadeOut()。感谢 @Xperiencing 让我回顾这个问题

所以在.ts

...
constructor(private ccService: NgcCookieConsentService){}
...
opencc(){
    this.ccService.fadeIn();
    //fadeOut to hide
}

然后在 html 中

<div (click)="opencc()">
    ...
</div