Created
April 12, 2018 12:33
-
-
Save GrandSchtroumpf/379c0cd68d16bc8193e445877709e26e to your computer and use it in GitHub Desktop.
The final eth.component.ts with NGRX selectors et store
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'; | |
// NGRX | |
import { Store, select } from '@ngrx/store'; | |
import { EthState, GetAccounts, getAccounts } from './ethereum'; | |
// RXJS | |
import { Observable } from 'rxjs/Observable'; | |
@Component({ | |
selector: 'app-root', | |
template: ` | |
<ul> | |
<li *ngFor="let address of addresses$ | async"> {{address}} </li> | |
</ul> | |
`, | |
styles: [] | |
}) | |
export class AppComponent implements OnInit { | |
public addresses$: Observable<string[]>; | |
public addresses: string[]; | |
constructor(private store: Store<EthState>) {} | |
ngOnInit() { | |
this.store.dispatch( new GetAccounts() ); | |
this.addresses$ = this.store.pipe(select(((getAccounts)))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment