I'm having some difficulties with Typescript.
If I would make a factory in AngularJS with Javascript like this:
;(function () { 'use strict';
angular.module('mercuryServices')
.factory('Ride', RideModelFactory);
RideModelFactory.$inject = [
'$http',
'$resource'
];
function RideModelFactory(
$http,
$filter,
$resource
) {
return {
get : function() {
return $http.get('/api/rides/');
},
save : function(
rideData
) {
//rideData.ridedate = $filter('date')(rideData.ridedate, "dd-MM-yyyy HH:mm:ss");
console.log(rideData);
return $http({
method: 'POST',
url: '/api/rides/',
headers: { 'Content-Type' : 'application/x-www-form-urlencoded' },
data: $.param(rideData)
});
},
delete : function(
id
)
{
return $http.delete("/api/rides/" + id);
},
update : function(
id,
rideEdit
)
{
return $http({
method: 'PATCH',
url: '/api/rides/' + id,
headers: { 'Content-Type' : 'application/x-www-form-urlencoded' },
data: $.param(rideEdit)
});
},
show : function(
id
)
{
return $http.get('/api/rides/' + id);
}
}
}
})();
How would this translate to Typescript? This is what I have so far, but I get the error: "Provider 'RideModelFactory' must return a value from $get factory method."
module mercuryServices {
'use strict';
export interface IRideModelFactory
{
Store(rideData: string[]);
}
export class RideModelFactory {
public static $inject = [
'$http'
];
http: ng.IHttpService;
constructor($http: angular.IHttpService) {
this.http = $http;
}
Store(rideData: string[])
{
return{
save: function(
rideData
){
console.log(rideData);
return this.http({
method: 'POST',
url: '/api/rides/',
headers: { 'Content-Type' : 'application/x-www-form-urlencoded' },
data: $.param(rideData)
});
}
}
}
}
angular.module('mercuryServices')
.factory('RideModelFactory', RideModelFactory);
}
constructor(public $http: angular.IHttpService)to avoid having to assign the injection in the constructor body)