Last active
April 25, 2016 09:20
-
-
Save thgreasi/f0f11fadd3c77f55d36439172d68475c to your computer and use it in GitHub Desktop.
AngularJS lifecycle app manager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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