Skip to content

Instantly share code, notes, and snippets.

@GrandSchtroumpf
Created April 12, 2018 11:54
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/b1327fb446be5615c8ce265fa1c5909c to your computer and use it in GitHub Desktop.
Save GrandSchtroumpf/b1327fb446be5615c8ce265fa1c5909c to your computer and use it in GitHub Desktop.
The Angular component with ngZone to interact with Ethereum
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