I have a base controller into which I inject a service called Uom. I call the service from my controller as follows:
Uom.get_measurement_unit_conversions().then( function( measurement_unit_conversions ) {
// Do some stuff here
});
and my service looks like...
angular.module('uomService', [])
.factory('Uom', function( $http ) {
return {
/**
* Will make a call to the restful API to get the
* measurement unit conversions and then return the formatted data.
*
* @return {float} Converted value
*/
get_measurement_unit_conversions: function()
{
var conversions = {};
$http({ method: 'GET', url: '/api/measurement_unit_conversions' })
.then( function( response ) {
angular.forEach( response.data.measurement_unit_conversions, function( object, key ) {
if( conversions.hasOwnProperty( object.source_measurement_unit_id ) == false )
{
conversions[object.source_measurement_unit_id] = {};
}
conversions[object.source_measurement_unit_id][object.target_measurement_unit_id] = object.formula;
});
return conversions;
});
}
}
});
but I keep getting the error
Uom.get_measurement_unit_conversions(...).then is not a function
I took my approach from another stack overflow question
What is the best practice for making an AJAX call in Angular.js?
Any idea what I am doing wrong?