As a newbie to AngularJS programming, I recently encountered an issue while trying to return an object from a service in a sample application. Here is the snippet of code from my custom service:
this.getCompanyInfo = function(companyID)
{
console.log( companyID );
angular.forEach( companyInfo, function( coInf ) {
if( coInf.companyID == companyID )
{
console.log(coInf);
return coInf;
}
})
}
Within this code, the variable companyInfo
holds an array with information about different companies represented by objects. The second console.log
displays the following output:
Object {companyID: "CHCL", companyName: "Chilime Hydropower", stockPriceTrend: Array[4]}
In my controller, the code looks like this:
$scope.companyInfo = dataServices.getCompanyInfo( $routeParams.companyID);
console.log($scope.companyInfo);
However, when I check the console, it shows 'undefined' instead.
I am unsure where I went wrong and would greatly appreciate any assistance!
Best regards.