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?
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.
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.
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.
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.
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
}
]
);
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