I just started learning angulerJS and created a factory to retrieve data from an API. However, I encountered an error when trying to use the factory in a controller.
Below is the code for the factory:
(function () {
var CategoriesFactory = function($http) {
var factory = {};
factory.getCategorys = function(account_id){
return $http.get('http://localhost:18678/api/Transaction?account_id=2');
};
factory.getTransaction = function(acc_id){
return $http.get('http://localhost:18678/api/Transaction?acc_id=2');
};
factory.getTransactionInCategory = function(category_id, from_date, to_date){
return.$http.get('http://localhost:18678/api/transaction?category='+category_id+'&account=2&from=2015-01- 01&to=2015-12-30');
};
return factory;
};
angular.module('AccApp').factory('CategoriesFactory', CategoriesFactory);
}());
Next is the controller:
app.controller('CategoriesController',
function ($scope, $routeParams, $http, CategoriesFactory) {
})
And here is the error message: Unknown provider: CategoriesFactoryProvider <- CategoriesFactory