Typically, I call a Factory from my Angular controller directly within the controller function without creating a separate method. For instance:
(function () {
'use strict';
angular.module("Dashboard")
.controller("DashboardController", DashboardController);
DashboardController.$inject = ["Interface"];
function DashboardController (Interface)
{
var vm = this;
/**
* Total Open Tickets
*/
Interface.openTickets().then(function (data) {
vm.tickets = objCount(data);
});
}
})();
I always display the total open tickets in my view, so there hasn't been a need for an additional method. However, I'm considering whether it would be more beneficial to make a separate method for the Interface
call and then initialize all methods like this:
function DashboardController (Interface)
{
var vm = this;
vm.getTickets = getTickets();
/**
* Total Open Tickets
*/
function getTickets() {
Interface.openTickets().then(function (data) {
vm.tickets = objCount(data);
});
}
}
I believe the second example is more organized and cleaner, so I am contemplating updating all of my code. Do you think this approach is correct?