Created
April 12, 2018 11:54
-
-
Save GrandSchtroumpf/b1327fb446be5615c8ce265fa1c5909c to your computer and use it in GitHub Desktop.
The Angular component with ngZone to interact with Ethereum
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, OnDestroy, NgZone } from '@angular/core'; | |
import { EthService } from './ethereum/eth.service'; | |
@Component({ | |
selector: 'app-root', | |
template: '<p>Current Account: {{ address }}', | |
styles: [] | |
}) | |
export class AppComponent implements OnInit, OnDestroy { | |
public address: string; | |
public alive = true; | |
constructor(private eth: EthService, private zone: NgZone) {} | |
ngOnInit() { | |
this.eth.currentAccount() | |
.subscribe((account: string) => this.zone.run(() => { | |
this.address = account; | |
})); | |
} | |
ngOnDestroy() { | |
this.alive = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment