Skip to content

Instantly share code, notes, and snippets.

@thgreasi
Last active April 25, 2016 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thgreasi/f0f11fadd3c77f55d36439172d68475c to your computer and use it in GitHub Desktop.
Save thgreasi/f0f11fadd3c77f55d36439172d68475c to your computer and use it in GitHub Desktop.
AngularJS lifecycle app manager
(function () {
"use strict";
window.appNamespace = window.appNamespace || {};
appNamespace.appManager = appNamespace.appManager || new AppManager();
function AppManager() {
this.currentAppName = '';
this.currentApp = null;
}
AppManager.prototype.startApp = function (appContainer, appName) {
if (this.currentApp) {
this.destroyApp();
}
var $appContainer = $(appContainer);
if (appContainer) {
this.currentAppName = appName;
this.currentApp = angular.bootstrap($appContainer[0], [appName]);
appNamespace.load();
}
};
AppManager.prototype.destroyApp = function () {
var $rootScope = this.currentApp.get('$rootScope');
$rootScope.$destroy();
this.currentAppName = '';
this.currentApp = null;
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment