I have a factory function that I need to implement in multiple controllers. The factory code block should be used inside the if condition of one controller and in the else condition of another controller. How can I achieve this using the factory? Any help or guidance on how to accomplish this task would be greatly appreciated.
Below is the code I have tried so far...
Factory.js
angular.module("App").factory('geoTreeFactory', function() {
return {
// If block function when conditions are true
getTreeCheck: function (geoLocation) {
// Code block for checking tree
},
// Else block function when conditions are false
getTreeUncheck: function(geoLocation) {
// Code block for unchecking tree
}
};
});
Controller.js
var selectedCtlGeoLocations = [];
var selectedCtlGeoLocationIds = [];
$scope.populateControlInPrcsGeoLoction = function(geoLocation) {
var pos = $.inArray(geoLocation.text, selectedCtlGeoLocations);
if (pos < 0) {
// Execute If block function of factory
geoTreeFactory.getTreeCheck();
} else {
// Execute Else block function of factory
geoTreeFactory.getTreeUncheck();
}
};