0.0.7 • Published 3 years ago

ng-context-api v0.0.7

Weekly downloads
-
License
-
Repository
github
Last release
3 years ago

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');
    }
}
0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago