This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Action } from '@ngrx/store'; | |
export enum ActionTypes { | |
Increment = '[Counter Component] Increment', | |
Decrement = '[Counter Component] Decrement', | |
Reset = '[Counter Component] Reset', | |
} | |
export class Increment implements Action { | |
readonly type = ActionTypes.Increment; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Action } from '@ngrx/store'; | |
import { ActionTypes } from './counter.actions'; | |
export const initialState = 0; | |
export function counterReducer(state = initialState, action: Action) { | |
switch (action.type) { | |
case ActionTypes.Increment: | |
return state + 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit, Injector } from '@angular/core'; | |
import { Store, select } from '@ngrx/store'; | |
import { Observable } from 'rxjs'; | |
@Component({ | |
selector: 'app-counter', | |
template: '<div>Current Count: {{ count$ | async }}</div>', | |
styleUrls: ['./counter.component.css'] | |
}) | |
export class CounterComponent implements OnInit { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// you can remove mat-raised-button color="" if you are not using material | |
// counter.increment.html | |
<button mat-raised-button color="primary" (click)="increment()">Increment</button> | |
// counter.decrement.html | |
<button mat-raised-button color="accent" (click)="decrement()">Decrement</button> | |
//counter.reset.html | |
<button mat-raised-button color="warn" (click)="reset()">Reset Counter</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NgModule, Injector } from '@angular/core'; | |
import { CommonModule } from '@angular/common'; | |
import { MatButtonModule } from '@angular/material/button'; | |
import { CounterComponent } from './counter.component'; | |
import { CounterIncrementComponent } from './counter-increment/counter-increment.component'; | |
import { CounterDecrementComponent } from './counter-decrement/counter-decrement.component'; | |
import { CounterResetComponent } from './counter-reset/counter-reset.component'; | |
import { StoreModule } from '@ngrx/store'; | |
import { counterReducer } from './counter.reducer'; | |
import { createCustomElement } from '@angular/elements'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { BrowserModule } from '@angular/platform-browser'; | |
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; | |
import { AppRoutingModule } from './app-routing.module'; | |
import { AppComponent } from './app.component'; | |
import { StoreModule } from '@ngrx/store'; | |
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; | |
import { CounterModule , counterReducer } from 'my-counter'; | |
@NgModule({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, Injector } from '@angular/core'; | |
import { createCustomElement } from '@angular/elements'; | |
import { | |
CounterComponent, CounterIncrementComponent, | |
CounterDecrementComponent, CounterResetComponent | |
} from 'my-counter'; | |
@Component({ | |
selector: 'app-root', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<counter-increment></counter-increment> | |
<counter-element></counter-element> | |
<counter-decrement></counter-decrement> | |
<counter-reset></counter-reset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div>Current Count: {{ count$ | async }}</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit } from '@angular/core'; | |
import { Store, select } from '@ngrx/store'; | |
import { Increment} from '../counter.actions'; | |
@Component({ | |
selector: 'app-counter-increment', | |
templateUrl: './counter-increment.component.html', | |
styleUrls: ['./counter-increment.component.css'] | |
}) | |
export class CounterIncrementComponent implements OnInit { |
OlderNewer