I define a factory in one file (Movie.ts), like this:
(function () {
'use strict';
angular
.module('moviesServices', ['ngResource'])
.factory('Movie', Movie);
Movie.$inject = ['$resource'];
function Movie($resource) {
return $resource('/api/movies/:id');
}
})();
Then I try to use it in another file (MoviesController.ts), note that it is TypeScript:
function MoviesAddController($scope, $location, Movie) {
$scope.movie = new Movie();
$scope.add = function () {
$scope.movie.$save(function () {
$location.path('/');
});
};
}
TypeScript now complains on "new Movie();" with the error message "Cannot resolve symbol 'Movie'."
How can I define that Movie is a factory? I tried exporting Movie as a class but I don't know how to convert the factory to a TypeScript class.
This works in JavaScript and the example is taken from this tutorial.