javascript - angular.bootstrap() - bootstrapping an angular app without the need for ng-app or ng-controller -


i trying create angular app can shipped , bootstrapped little no directives. ideally include js file:

<script src="myapp.js"></script> 

then put div on page:

<div id="mydiv"></div> 

and bootstrap app like:

angular.bootstrap(document.getelementbyid('mydiv'),['myapp']); 

this, needless say, doesn't work.

see this fiddle see working ng-* directives in place , this one without.

i guess question - possible?

ideally, i'd implement app similar stripe:

<script   src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button"   data-key="pk_test_czwzktp2tactuloeoqbmtrzg"   data-amount="2000"   data-name="demo site"   data-description="2 widgets ($20.00)"   data-currency="usd"   data-image="/128x128.png"> </script> 

but couldn't find way work either. main goal not have expose angular specifics use app.

you can "cheat" little bit using jquery add ng-controller attribute div after fact.

$(function() {     $('#main_container').attr('ng-controller', 'inventorycontroller');     $.when(angular.bootstrap(document.getelementbyid('main_container'), ["inventorymodule"])).done(function() {         console.log("app bootstrapped");     }); }); 

fiddle : http://jsfiddle.net/tj24k/

essentially, though, angular works adding directives templates. if want clean templates start, you'll need directive adding in jquery. me, seems more work it's worth. whole beauty of angular doing away jquery selectors.

ps., changed controller set $scope.items instead of returning it.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -