I'm looking to break up my code into smaller controllers instead of having everything in one large controller. However, I've come across this error:
Argument 'protocolController' is not a function, got undefined
I've created a factory for handling requests:
/*
FACTORY THAT HANDLES ALL REQUESTS.
*/
function asyncFactory() {
var factory = this;
factory.list = [];
this.update = function(restUrl) {
return $http.get(restUrl)
.success(function(data){
factory.list = data;
})
.error(function(data){
console.log('Error: ' + data);
});
};
// Other functions like add, remove, and change...
}
And here's the controller that uses the factory:
/*
PROTOCOL CONTROLLER
*/
function protocolController(asyncFactory){
var controller = this;
controller.list = asyncFactory.list;
controller.formData = {};
// Functions like getUpdatedList, addData, removeData, and editData...
}
To call it, use this approach:
/*
MAIN - WHERE THE CONTROLLER AND FACTORY IS CALLED
*/
var app = angular.module('TransactionMonitoring', [])
.controller('protocolController', protocolController(asyncFactory));