How do you call a factory? As defined below.
angular.module('fb.services', []).factory('getQueryString', function () {
return {
call: function () {
var result = {}, queryString = qs.substring(1),
re = /([^&=]+)=([^&]*)/g,
m;
while (m = re.exec(queryString))
result[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
return result;
}
}
});
alert(getQueryString.call('this=that&me=you'));
If you want to call your factory outside of the angular you would need to get an injector from your module. i.e:
angular.injector(['fb.services']).get('getQueryString').call();
You can typically use this while writing unit test, but you should try to avoid doing this in production code.
Try not to access angular app outside, Otherwise typical usage of the factory/services etc would be through dependency injection while you are in the app.
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