我想显示我得到的CSV
数据,以显示输出如下:
Price: 955.99
EPS: 29.59
Date : 7/14/2017
但是,我得到如下输出:
它连续显示,与col0
,col2
,col4
分开。
col0
col2
col4
yahooStock.js
angular.module('app').factory('yahooStock',function($http){
//yahoo query api
var yqlUrl = "https://query.yahooapis.com/v1/public/yql";
//historical api queryied 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>
我已连接了plunker链接。
答案 0 :(得分:3)
<p>Price: {{data.col0}}</p> //col0 is price
<p>EPS: {{data.col2}}</p> // col2 is EPS
<p>Date: {{data.col4}}</p> //col44 is Date
// col1和col3为null,如果不相关则删除它们。