Showing the CSV
data that was retrieved, with the desired output as follows:
Price: 955.99
EPS: 29.59
Date : 7/14/2017
Unfortunately, the actual output appears like this:
https://i.sstatic.net/zMVCo.png
The data is displayed in a row, separated by col0
,col2
,col4
.
- Price is
col0
- EPS is
col2
- Date is
col4
yahooStock.js
angular.module('app').factory('yahooStock',function($http){
//yahoo query api
var yqlUrl = "https://query.yahooapis.com/v1/public/yql";
//historical api queried by yql..
var historicalUrl = 'https://finance.yahoo.com/d/quotes.csv';
//template to put query params into
var queryTemplate = _.template("select * from csv where url='" + historicalUrl + "?s=<%= symbol %>&f=<%= code %>'");
function _request(symbol,code){
return $http({
method:"GET",
url: yqlUrl,
params: {q: queryTemplate({symbol:symbol,code:code}), format: 'json'}
}).then(function(response){
console.log('response',response.data);
return {data:response.data.query.results.row};
});
}
var factory = {
getYahooData: function(symbol){
return _request(symbol, 'l1,e,d1');},
};
return factory;
});
main.js
angular.module("app",['ionic']).controller("mainCtrl",function($scope,yahooStock){
yahooStock.getYahooData('GOOG').then(function(response){
$scope.data = response.data;
});
});
.html
<ion-content has-header="true">
<p>Price: {{data}}</p>
<p>EPS: {{data}}</p>
<p>Date: {{data}}</p>
<!-- our list and list items -->
<ion-list>
<ion-item ng-repeat="stock in stocks">
{{stock.title}}
</ion-item>
</ion-list>
</ion-content>
Provided the Plunker link for reference.