1.0.7 • Published 5 months ago

ngx-cookie-banner-gg v1.0.7

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

ngx-cookie-banner-gg

Forked from https://github.com/exportarts/ngx-cookie-banner

lerna npm Build Status Quality Gate Status

Motivation

This lib is inspired by angular2-cookie-law which is discontinued. Therefore, I rewrote the main functionality and removed much of the opinionated styles and behaviour.

Getting Started

Install the dependency

npm i --save-exact ngx-cookie-banner-gg

Import NgxCookieBannerModule

import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { NgxCookieBannerModule } from "ngx-cookie-banner";

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    NgxCookieBannerModule.forRoot({
      cookieName: "ngx-cookie-banner-demo-app",
    }),
  ],
  providers: [],
  bootstrap: [AppComponent],
})
export class AppModule {}

Use the component

<!-- app.component.html -->

<ngx-cookie-banner #cookie>
  <div class="banner-inner">
    <span>
      We use Cookies!
      <a role="button" (click)="cookie.dismiss()">dismiss</a>
    </span>
  </div>
</ngx-cookie-banner>
/* app.component.scss */

.banner-inner {
  background: red;
}
.banner-inner a {
  font-weight: bold;
  cursor: pointer;
}
/* app.component.ts */

@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.scss"],
})
export class AppComponent implements AfterViewInit, OnDestroy {
  @ViewChild("cookie", { static: true })
  banner: NgxCookieBannerComponent;

  private _cookieSub: Subscription;

  // It is currently necessary to manually subscribe at this
  // point to initialize the banner component.
  ngAfterViewInit() {
    this._cookieSub = this.banner.isSeen.subscribe();
  }

  ngOnDestroy() {
    this._cookieSub.unsubscribe();
  }
}
1.0.7

5 months ago

1.0.6

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

2 years ago

1.0.0

2 years ago