Join the Stack Overflow Community
Stack Overflow is a community of 6.5 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

What I need is to bootstrap AngularJs and render a directive on demand. Imagine there is a splash page that should not be resources-hungry (should not download much without need, even javascript at the bottom would be bad).

<!DOCTYPE html>
<body>
    <button onclick="loadTheApp()">Launch app</button>
    <script>
        function loadTheApp() {
            // load Angular and other files in this manner:
            var el = document.createElement('script');
            el.src = '/js/app.js';
            document.body.appendChild(el);

            // TODO: bootstrap Angular and render directive   
        }
    </script>
</body>
</html>
share|improve this question
1  
possibly something like this? – Grundy Aug 3 '15 at 18:25

I think you can use this solution:

el.onload = function() {
  var element = document.body; // element which contains angular application   

  angular.bootstrap(element, ['myApp']);
}

assuming that app.js file contains angular and application (build version), or angular is loaded and app.js file contains application myApp

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.