Guest User

Untitled

a guest
Oct 20th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. import { Injectable } from '@angular/core';
  2.  
  3. @Injectable()
  4. export class MyService {
  5.  
  6. private connection;
  7.  
  8. constructor() {
  9.  
  10. this.connect().then((connection) => {
  11. this.connection = connection;
  12. // Components should be able to consume this service once execution reaches this point, but not before!
  13. });
  14.  
  15. }
  16.  
  17. private connect(): Promise<any> {
  18. // (return some promise which will eventually resolve with a connection)
  19. }
  20.  
  21. public getData(key: string): string {
  22. // (this method won't be usable until the .then() in the constructor has run)
  23. }
  24.  
  25.  
  26. }
Add Comment
Please, Sign In to add comment