I am facing a challenge with my Angular (v. 1.6.3) app where I have fetched a JSON object containing stock price data. The structure of the JSON object only allows querying using brackets, with each key being a string that may include spaces, parentheses, periods, and other characters.
{ "Time Series (Daily)":
"2017-11-17":
"4. close": "82.4000"
"2017-11-18":
"4. close": "79.2000"
}
In my controller, I have assigned this JSON object to a variable ($scope.stocks
) and attempted to create a way to dynamically update the displayed data in my HTML:
$scope.thisStock = $scope.stocks["Time Series (Daily)"][$scope.currentDate]["4. close"];
The $scope.currentDate
value changes based on user input from the form in the HTML (for instance, through sliding a widget to select the current date for displaying the closing price of the stock).
Below is the HTML code intended to dynamically show the closing stock price based on the selected date:
{{thisStock | currency}}
I have verified that $scope.currentDate
provides the correct date string format and that statically querying $scope.stocks
works as expected. However, the issue lies in making the dynamic display work as intended. Currently, it seems that $scope.currentDate
is being interpreted as a string rather than a variable, resulting in an invalid query message.
I suspect that I might be approaching this problem incorrectly. Any guidance would be greatly appreciated!