Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve AngularJS app name

Tags:

angularjs

How can I retrive the name of the current app in AngularJS?
I mean the ng-app="foo" value.
I have searched through the API documentation, but I could not find any reference to this.

MY SOLUTION
Actually I have found solution like this

angular.element($('[ng-app]')).attr('ng-app');  

But I don't really like the idea to search through DOM just to get this information.
Do you know a better solution?

like image 322
pasine Avatar asked Jul 06 '13 10:07

pasine


People also ask

Where can I find AngularJS application?

The best way to check is to write "angular" on browser console. If you get any object [With child objects as "bind","bootstrap","callbacks","module" etc.] then its an angular web app.

What is app run in AngularJS?

Run blocks are the closest thing in AngularJS to the main method. A run block is the code which needs to run to kickstart the application. It is executed after all of the services have been configured and the injector has been created.

What is Angular module ()?

An AngularJS module defines an application. The module is a container for the different parts of an application. The module is a container for the application controllers. Controllers always belong to a module.

Can I connect Angular with Python?

Now you can run both the Angular frontend and Python backend together to see the final result. As you might have noticed, your Python REST API is listening to the port 4433 while the Angular application is being served by a process on port 8080.


1 Answers

From the $rootElement docs:

The root element of Angular application. This is either the element where ngApp was declared or the element passed into angular.bootstrap.

If you inject it you can get the main module name without scanning the DOM:

<html ng-app="myApp">
...
app.controller('MyCtrl',
  [
    '$scope', 
    '$rootElement', 
    function($scope, $rootElement) {
      console.log($rootElement.attr('ng-app')); // --> myApp
    }
  ]
);
like image 61
Stewie Avatar answered Oct 22 '22 02:10

Stewie