Okei Okei - 1 year ago 105
AngularJS Question

Angular 1 - Get the module a controller is running in

I am working inside a platform where you can create controllers using a web form and write angular code inside of them... but I do not have access to the parent module.

So here I am in my module, trying to apply a filter but I cannot apply a filter if I do not know the module.

Is there any way I can find out what module I am running in from a controller?

I only have access to this code:

function ($scope, spUtil, snRecordWatcher, $rootScope) {


I cannot see the angular.module(blabla)

Thank you,
Alexandru S.

Lex Lex
Answer Source

If you inject $rootElement you can use it to find the name of the module under which the current controller is running. e.g.:

function ($scope, spUtil, snRecordWatcher, $rootScope, $rootElement) {
    var module = $rootElement.attr('ng-app');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download