I'm thinking that I am not doing some part of this the "Angular Way" because I can't find similar use cases anywhere in the docs.
My input takes comma-separated inputs, and calls this function using ng-submit(within weatherController):
$scope.submit = function() {
var rawZipString = this.text;
var strippedString = rawZipString.replace(/\s+/g, '');
var zipArray = strippedString.split(',');
for(i=0;i<zipArray.length;i++){
Weather.getWeatherForecast(zipArray[i])
.then(function(forecast){
$scope.temperatures.push(forecast);
})
}
/** Create weather objects */
for(i=0;i<$scope.temperatures.length;i++){
var tempForecast = new weatherConstructor(zipArray[i],$scope.temperatures[i]);
$scope.zipForecast.push(tempForecast);
}
/** Format as JSON */
$scope.DOMdata = angular.toJson($scope.zipForecast);
console.log($scope.DOMdata);
}
This is weatherConstructor:
function weatherConstructor(zip,temp){
this.zip = zip;
this.temp = temp;
}
I'm unsure of how to then take the constructed JSON object ($scope.DOMdata) and push it to the view, which looks like this:
<div ng-controller="weatherController">
<h4 ng-repeat="DOM in DOMdata">
{{DOM.zip}} now is {{DOM.temp}}
</h4>
getWeatherForecastruns asynchronously, but you are trying to use the results synchronously.