2
votes

I have an angular module / factory like this:

var app = angular.module('webportal', ['vr.directives.slider', 'angular-flexslider', 'LocalStorageModule', 'multi-select']);

    app.factory('portal', ['uri', function (uri) {
        portal = {};
        portal.getURLParameter = function (name) {
            var hash;
            var vars = [];

            var indexOfQuestion = window.location.href.indexOf('?');

            if (indexOfQuestion != -1) {

                var hashes = window.location.href.slice(indexOfQuestion + 1).split('&');
                for (var i = 0; i < hashes.length; i++) {

                    if (typeof name == 'undefined')
                        vars.push(hashes[i]);

                    else {
                        hash = hashes[i].split('=');
                        if (hash[0] = name)
                            return hash[1];
                    }
                }
            }
        };
        return portal;
    }]);

Now i am trying to call the getURLParameter from outside angular, like this:

angular.injector(['webportal']).get('portal').getURLParameter('blah');

Of course that does not work and fails with:

Error: [$injector:modulerr] Failed to instantiate module webportal due to: [$injector:modulerr] Failed to instantiate module vr.directives.slider due to: [$injector:modulerr] Failed to instantiate module ngTouch due to: [$injector:unpr] Unknown provider: ngClickDirectiveProvider http://errors.angularjs.org/1.2.25/$injector/unpr?p0=ngClickDirectiveProvider minErr/......

So can anyone tell me what is the proper way to call this?

1
yes it works fine.this is just part of a very large file i trimmed down and pasted here.Shrouk Khan
Or do angular.injector(['ng','webportal']).getPSL
yup this i like better than using document.body. thankyouShrouk Khan
Reason is because one of your module has dep on ng-Touch which actually uses ngClickDirective provider from angular core. So you need ng as well, but you mostly always would need to include ngPSL

1 Answers

6
votes

found the answer after poking around a bit more:

angular.element(document.body).injector().get('portal').getURLParameter('blaha')