Displaying only one piece of information instead of multiple pieces of information from a row in Javascript

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.

https://plnkr.co/edit/4bxI8Qd8ftVfaE4D7veN?p=preview

Answer №1

<p>Current Price: {{data.col0}}</p> //col0 represents current price
<p>Earnings Per Share: {{data.col2}}</p> // col2 corresponds to EPS
<p>Date Updated: {{data.col4}}</p> //col44 indicates date of last update

//col1 and col3 are not applicable, feel free to remove them if necessary.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the process for exporting a chart into Excel?

My current challenge involves displaying data extracted from a database in the form of a bar chart and then exporting both the data and the chart as an image into an Excel file. While I have successfully displayed the bar chart, I am facing difficulties in ...

Guide on setting up factories with pre-existing relationships in MIKRO-ORM

Hey there! I'm currently exploring how to set up a factory and establish relationships between models. For instance, I have a UserFactory that corresponds to the User entity which is connected to the userType table. However, in the factory, I'm ...

Having difficulty interacting with a button using Selenium and JavaScript

For some reason, I am experiencing difficulty in clicking the login button even though my code appears to be accurate and there are no iframes or windows present: const { Builder, By, Key, until } = require('selenium-webdriver'); const { expect ...

Alternative methods for submitting form data without dependency on ngClick and ngSubmit

Is it possible to send data in AngularJS without using ngClick or ngSubmit, as these methods require explicitly mentioning the function name which may pose security concerns? This is the code snippet I am currently using: <form name="userForm" noval ...

Is there a way to retrieve the id of a jQuery autocomplete input while inside the onItemSelect callback function?

I am currently utilizing the jquery autocomplete plugin created by pengoworks. You can find more information about it here: Within the function that is triggered when an entry is selected, I need to determine the identifier of the input element. This is i ...

Using jquery to navigate back to the search results page

I am trying to figure out how to use jquery to return to the search results page, but my current code always takes me back to the main data instead of the search results. Can anyone help me with this issue? $(document).ready(function() { $("#kembali ...

Trigger function in a different child component on mouse up

Trying to call a function in a child component from another child component in ReactJS. Specifically, I want to trigger a function in another component when the 'mouseup' event happens. Here is an illustration of what I am attempting to achieve: ...

Double-tap bug with Image Picker in Typescript React Native (non-expo)

Well, here’s the situation - some good news and some bad news. First, the good news is that the code below is functioning smoothly. Now, the not-so-good news is that I find myself having to select the image twice before it actually shows up on the clie ...

Utilizing Selenium to locate an element by its class name and then deleting it from the document object model through

I have found a code that worked really well for me. It involves getting the quantity of messages first and then removing them from the DOM. public static void RemoveMessages() { // Removing messages from the DOM using JavaScript ...

When utilizing the get method to invoke a JavaScript function, IE imposes a restriction of 2083 characters

I need assistance with passing a lengthy XML string to a JavaScript function. Currently, the process involves using an XSL file to generate HTML code which includes a link that triggers the function like this. <a href="javascript:myFunctionName('l ...

How can I handle a 404 error if an object is not found in a JSON file?

Below is my code snippet where I check for the correct req.path and display specific text. However, I now need to show a 404 not found error message. I attempted placing it inside the for loop condition with break;, but it's not quite working as expe ...

`Angular Image Upload: A Comprehensive Guide`

I'm currently facing a challenge while attempting to upload an image using Angular to a Google storage bucket. Interestingly, everything works perfectly with Postman, but I've hit a roadblock with Angular Typescript. Does anyone have any suggesti ...

Next.js is causing me some trouble by adding an unnecessary top margin in my index.js file

I started a new project using next.js by running the command: yarn create next-app However, I noticed that all heading and paragraph tags in my code have default top margins in next.js. index.js import React, { Component } from "react"; import ...

Leveraging jQuery's .when and .then methods allows for

I'm attempting to utilize a shared ajax function that is meant to retrieve the value returned from the PHP script. function fetchAjax(url, data, type) { result = 0; $.when( $.ajax({ type: "POST", url: url, data: data, ...

Selecting an object dynamically to add a new property in JavaScript

I am faced with a scenario where I have two objects and I need to add new properties to them. The challenge is that I want to be able to choose which object to work with first before adding the new properties. Here's the proposed logic : let customiz ...

What is the best way to utilize typed variables as types with identical names in Typescript?

Utilizing THREE.js with Typescript allows you to use identical names for types and code. For instance: import * as THREE from '/build/three.module.js' // The following line employs THREE.Scene as type and code const scene: THREE.Scene = new THRE ...

Exploring the differences in jQuery

Here is a snippet of my jQuery function: $(function() { $('.submitButton').click(function(){ $('input').each(function() { if ($(this).attr('min')) { if ($(this).val()<$(this).attr ...

The controller in ng-controller returns an undefined error when loaded using RequireJs

I have encountered an issue while loading the Angular application using requirejs. The ng-controller written in main.html loads directly but ends up being undefined. app.js define(['sfongApp', 'ng-grid', 'angular-bootstrap'] ...

PHP strtotime is adding an extra hour to my time

Within my database table, I have a datetime stored as '2014-08-05 15:12:00'. After using strtotime() to convert this date to milliseconds, on the client side I create a new Date object as follows: var date = new Date(date_in_milliseconds) Ho ...

modify the class's CSS style

Hey there! I'm having an issue with my code snippet. My goal is to change the background color of both fields with the class 'navicon', as shown in the function fu(). However, it's not working as expected. Changing the color based on id ...