'use strict';

var EventEmitter = require('events').EventEmitter;

module.exports = function(angular) {

  var App = function(angularApp, config) {
    this._name = config.name;
    this._cssUrl = config.cssUrl;
    this._angularApp = angularApp;
    this._eventEmitter = new EventEmitter();
    this._api = null;

    this._angularApp.on('started', function(api) {
      this._api = api;
      this._eventEmitter.emit('initialized', api);
    }.bind(this));
  };


  App.prototype = {

    runAngularApp: function() {
      this._angularApp.registerModules();
      this._inject();
      this._bootstrap();
    },


    _inject: function() {
      this._injectHtml('<app id="' + this._name + '"></app>');
      this._injectCss(this._cssUrl);
    },


    _bootstrap: function() {
      angular.bootstrap(document.getElementById(this._name), [this._name]);
    },


    getApi: function() {
      return this._api;
    },


    on: function(name, cb) {
      this._eventEmitter.on(name, cb);
    },


    _injectHtml: function(content) {
      angular.element(document.body).append(content);
    },


    _injectCss: function(path) {
      var head = document.getElementsByTagName('head')[0];
      var link = document.createElement('link');
      link.setAttribute('href', path);
      link.setAttribute('rel', 'stylesheet');
      link.setAttribute('type', 'text/css');
      head.appendChild(link);
    }

  };

  return App;

};

@@ -205,16 +205,56 @@
 cssUrl;%0A
+    this._container = config.container;%0A
     this
@@ -346,16 +346,45 @@
  = null;
+%0A    this._appElement = null;
 %0A%0A    th
@@ -721,56 +721,51 @@
 is._
-injectHtml('%3Capp id=%22' + this._name + '%22%3E%3C/app%3E'
+createAppElement();%0A      this._injectHtml(
 );%0A 
@@ -785,28 +785,16 @@
 jectCss(
-this._cssUrl
 );%0A    %7D
@@ -854,43 +854,24 @@
 rap(
-document.getElementById(this._name)
+this._appElement
 , %5Bt
@@ -1019,32 +1019,134 @@
 , cb);%0A    %7D,%0A%0A%0A
+    _createAppElement: function() %7B%0A      this._appElement = angular.element('%3Capp%3E%3C/app%3E');%0A    %7D,%0A%0A%0A
     _injectHtml:
@@ -1155,23 +1155,16 @@
 unction(
-content
 ) %7B%0A    
@@ -1181,16 +1181,35 @@
 element(
+this._container %7C%7C 
 document
@@ -1222,20 +1222,29 @@
 .append(
-cont
+this._appElem
 ent);%0A  
@@ -1275,20 +1275,16 @@
 unction(
-path
 ) %7B%0A    
@@ -1423,12 +1423,20 @@
 f', 
-pa
 th
+is._cssUrl
 );%0A 

Remove id generation on element and add possibility for container elements