I'm developing an angular component for our company. It will be used by several applications. Some of them are using angular, others aren't.
Therefore, the component should be able to run in 3 cases:
- when the application is not using angular
- when the application is bootstrapped using an ng-app attribute
- when the application is manually bootstrapped using angular.bootstrap()
I'm required to use the existing angular app when possible.
I already solved cases 1 and 2, but in case 3, I'm having problems retrieving the name of the existing app.
Which function in angular can I use to get the name of a manually bootstrapped app?
This is what I have (in typescript):
var ngAppFound: boolean = true;
function createOrGetApp(): ng.IModule {
var appName: string = angular.element("[ng-app]").attr("ng-app");
if (appName == undefined) {
appName = "myApp";
ngAppFound = false;
return angular.module(appName, []);
}
return angular.module(appName);
}
createOrGetApp();
$(function () {
if (!ngAppFound) {
// how to check whether already manually bootstrapped?
// and how to retrieve the app name?
angular.bootstrap(document, ["myApp"]);
}
});