Advertisement
Guest User

Untitled

a guest
Aug 27th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. {
  2. "site": {
  3. "success": true,
  4. "title": "foo",
  5. "description": "bar"
  6. }
  7. }
  8.  
  9. import { Injectable } from '@angular/core';
  10. import {HTTP_PROVIDERS, Http, Response, Headers, RequestOptions } from "@angular/http";
  11. import { Observable } from 'rxjs/Rx';
  12.  
  13.  
  14. @Injectable()
  15. export class ContentService {
  16. constructor(private _http:Http) {}
  17.  
  18. getContent() {
  19. return this._http.get('http://localhost:8080/api/foobar-endpoint/')
  20. .map((res:Response) => res.json())
  21. }
  22.  
  23. }
  24.  
  25. import { Component, OnInit } from '@angular/core';
  26. import { ContentService } from "../../services/content/content.service";
  27.  
  28. const template = require('./home.jade');
  29. const styles = require('./home.sass');
  30.  
  31. @Component({
  32. selector: 'home',
  33. templateUrl: template,
  34. styleUrls: [styles]
  35. })
  36.  
  37. export class HomeComponent implements OnInit {
  38.  
  39. public foo = {}
  40.  
  41. constructor(private _contentService: ContentService) {}
  42.  
  43. ngOnInit() {
  44. this.getContent();
  45. }
  46.  
  47. getContent() {
  48. this._contentService.getContent()
  49. .subscribe(
  50. data => {this.foo = data},
  51. err => { console.log(err) },
  52. () => console.log()
  53. );
  54. }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement