Skip to content

Commit

Permalink
feat(examples): use HttpClientModule and HttpCLient instead of deprec…
Browse files Browse the repository at this point in the history
…ated Http
  • Loading branch information
tomastrajan committed Sep 26, 2017
1 parent 4e8f0ab commit 167556b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
Empty file modified CHANGELOG.md
100755 → 100644
Empty file.
Empty file modified package.json
100755 → 100644
Empty file.
4 changes: 2 additions & 2 deletions src/app/core/core.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HttpModule } from '@angular/http';
import { HttpClientModule } from '@angular/common/http';
import { StoreModule } from '@ngrx/store';
import { EffectsModule } from '@ngrx/effects';

Expand All @@ -16,7 +16,7 @@ export function getInitialState() {
imports: [
// angular
CommonModule,
HttpModule,
HttpClientModule,

// ngrx
StoreModule.forRoot({
Expand Down
14 changes: 8 additions & 6 deletions src/app/examples/stock-market/stock-market.service.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';

import { Stock } from './stock-market.reducer';

const PROXY_URL = 'https://cors-anywhere.herokuapp.com/';
const API_URL = 'http://finance.google.com/finance/info?client=ig&q=NYSE:';
const API_URL = 'https://finance.google.com/finance?output=json&q=NYSE:';

@Injectable()
export class StockMarketService {

constructor(
private http: Http
private httpClient: HttpClient
) {}

retrieveStock(symbol: string): Observable<Stock> {
return this.http.get(PROXY_URL + API_URL + symbol)
.map((res: Response) => JSON.parse(res.text().replace('//', ''))[0])
return this.httpClient
.get(PROXY_URL + API_URL + symbol, { responseType: 'text' })
.map((res: string) => JSON.parse(res.replace('//', ''))[0])
.map((stock: any) => ({
symbol: stock.t,
exchange: stock.e,
last: stock.l,
ccy: stock.l_cur.replace(stock.l, ''),
ccy: 'USD',
change: stock.c.substr(1),
changePositive: stock.c.indexOf('+') === 0,
changeNegative: stock.c.indexOf('-') === 0,
Expand Down

0 comments on commit 167556b

Please sign in to comment.