Skip to content

Instantly share code, notes, and snippets.

@GrandSchtroumpf
Created April 12, 2018 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GrandSchtroumpf/379c0cd68d16bc8193e445877709e26e to your computer and use it in GitHub Desktop.
Save GrandSchtroumpf/379c0cd68d16bc8193e445877709e26e to your computer and use it in GitHub Desktop.
The final eth.component.ts with NGRX selectors et store
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