Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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