Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. tmp: string;
  2.  
  3. constructor(private http: Http) {
  4. this.tmp = "load";
  5. this.GetUsers();
  6. }
  7.  
  8. ngOnInit() {
  9. setTimeout(console.log("Hello"), 2000);
  10. }
  11. GetUsers() {
  12. this.http.get('http://localhost:1337/api/users')
  13. .toPromise()
  14. .then(function(response) {
  15. this.tmp = "success"
  16. })
  17. .catch(this.handleError);
  18.  
  19. public tmp: string;
  20.  
  21. constructor(private http: HttpClient) { // не забудь заимпортить этот модуль
  22.  
  23. }
  24.  
  25. ngOnInit() {
  26. setTimeout(console.log("Hello"), 2000);
  27. this.GetUsers()
  28. .do(() => this.tmp = 'load')
  29. .subscribe(data => {
  30. this.tmp = data;
  31. });
  32. }
  33.  
  34. private getUsers(): Observable<any> {
  35. return this.http.get<any>('http://localhost:1337/api/users')
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement