Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Injectable } from '@angular/core';
- @Injectable()
- export class MyService {
- private connection;
- constructor() {
- this.connect().then((connection) => {
- this.connection = connection;
- // Components should be able to consume this service once execution reaches this point, but not before!
- });
- }
- private connect(): Promise<any> {
- // (return some promise which will eventually resolve with a connection)
- }
- public getData(key: string): string {
- // (this method won't be usable until the .then() in the constructor has run)
- }
- }
Add Comment
Please, Sign In to add comment