In my controller, I invoke a factory function that needs to call itself recursively. The code worked when they were just simple javascript functions not defined within the factory, but I am trying to isolate them a bit better.
This is what a snippet of code looks like in the controller:
myApp.controller('VisionCtrl', ['$scope', 'AppFactory', function ($scope, AppFactory,) {
var promiseTaxo;
promiseTaxo = AppFactory.getTaxonomy("vision3", "Vision Type");
}])
and in the factory module:
myApp.factory('AppFactory', ['$http', '$q', function($http, $q, TaxoFactory) {
return {
getTaxonomy: function(group, termSet) {
... lots of code ....
if (termSet.length > 0) { getTaxonomy(group, childTermSet) }
}
}
}])
This is super simplified, but the idea is that in the getTaxonomy function, if I find children node, I recursively call myself. There is a whole lot more stuff going on where I handle the asynch nature of the processing and the promises, but when I put this code outside the factory, it works just fine.
I just don't know how to invoke the getTaxonomy inside the getTaxonomy!
You can either call this.getTaxonomy()
as @elclanrs mentioned or change up your factory a bit so you can call it from inside:
myApp.factory('AppFactory', ['$http', '$q', function($http, $q, TaxoFactory) {
var AppFactory = {
getTaxonomy: function(group, termSet) {
... lots of code ....
if (termSet.length > 0) { AppFactory.getTaxonomy(group, childTermSet) }
}
}
return AppFactory;
}]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With