I am trying to get a stock quote from yahoo's api and I am using angular's $http.jsonp method. The goal is when the result comes back, to have the app go to the this route: '/stocks/show_stock'. I am trying to do it in two ways and neither works 1) I put the statement:
window.location = '/stocks/show_stock'
in the callback function that wraps the JSONP response 2) I put the statement:
$location.path '/stocks/show_stock'
in the HTTPpromise callback. (see the comments in the code)
Here is my code (in coffescript):
#THIS IS THE CALLBACK FUNCTION THAT I SEND WITH THE JSONP REQUEST
window.stock_quote_callback = (data)->
console.log data #THIS WORKS AND I CAN SEE THE DATA RETURNED FROM YAHOO
window.stock_quote_result = data.results
alert 'I am in the callback'
#THE STATEMENT BELOW DOES NOT WORK EVEN THOUGH I CAN SEE THE ALERT ABOVE
window.location = '/stocks/show_stock'
angular.module('Services').service 'StockSupplier', ($http)->
get_stock = (symbol)->
q = 'select * from yahoo.finance.quotes
where symbol in ("'+symbol+'")
&format=json&
diagnostics=true&
env=http://datatables.org/alltables.env&
callback=stock_quote_callback'
url = 'http://query.yahooapis.com/v1/public/yql?q='+q
$http.jsonp(url).then (data)->
#THE CODE BELOW NEVER EXECUTES EVEN THOUGH RESULT IS RETURNED
alert 'This should pop up when result returns'
$location.path'/stocks/show_stock'
{
get_stock: (symbol)-> get_stock(symbol)
}
Thank you in advance.