ng-context-api
TypeScript icon, indicating that this package has built-in type declarations

0.0.7 • Public • Published

NgContext

Angular Context API Module Inspired By React Context API

npm i ng-context-api

npm : https://www.npmjs.com/package/ng-context-api

Usage

Setting

// in app module

import {NgContextModule} from 'ng-context-api';

@NgModule({
  declarations: [
      ...
  ],
  imports: [
      ...
    NgContextModule // import this module
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Provider

<ng-context-provider name="colorProvider" value="red">
    <app-consumer></app-consumer>
</ng-context-provider>

<ng-context-provider name="colorProvider" value="blue">
    <app-consumer></app-consumer>
</ng-context-provider>

Consumer

@Component({
    selector:'app-consumer',
    ...
})
export class Consumer implements OnInit{
    selectContext$;
    constructor(private context: ContextConsumerService){}

    ngOnInit(): void{
        this.selectContext$ = this.context.select<string>('colorProvider');
    }
}

Package Sidebar

Install

npm i ng-context-api

Weekly Downloads

1

Version

0.0.7

License

none

Unpacked Size

49.7 kB

Total Files

18

Last publish

Collaborators

  • lacomaco