2

I have been using this code to bootstrap AngularJS:

angular.bootstrap(angular.element("body")[0], ["stApp"]);

However now I decided not to use jQuery and I am getting the message "selectors not implemented"

Is there a way I can resolve this without have to use the jQuery selector?

Alan2
  • 23,493
  • 79
  • 256
  • 450
  • Can you use `ng-app` instead of manually bootstrapping? If so, just add it to your `body` element. – Mark Rajcok Jun 17 '13 at 17:44
  • I am loading AngularJS at the bottom of my document. Correct me if wrong but I believe for this I need to do a manual bootstrap after AngularJS is loaded. – Alan2 Jun 17 '13 at 17:47

1 Answers1

2

First of all, you can use ng-app even if you load AngularJS script at the bottom of a page, there shouldn't be any problem with this.

And yes, if you don't include jQuery AngularJS falls-back to so called jqLite - a minimal subset of jQuery APIs needed for proper functioning of AngularJS. As mentioned on http://docs.angularjs.org/api/angular.element the only selectors implemented in jqLite are tag name selectors. So If you really want to do manual bootstrapping you should change your code to:

angular.element(document).ready(function() {
  angular.bootstrap(angular.element(document).find('body'), ['stApp']);
});

Here we are only using a tag-name selector so find is working as expected, even without jQuery included. Demo plunk: http://plnkr.co/edit/xsE02zWxK993FTXtWUbp?p=preview

pkozlowski.opensource
  • 117,202
  • 60
  • 326
  • 286
  • Can you check the following answer to a similar question: http://stackoverflow.com/questions/16537783/which-method-should-i-use-to-manually-bootstrap-my-angularjs It seems to suggest that I must do a manual bootstrap. "They are roughly the same, with a few differences: angular.bootstrap(document, ['TodoApp']); This will work if you have your scripts loaded at the end of the page (instead of in the header). Otherwise, the DOM will not be loaded at the time of bootrsaping the app (there won't be any template to be compiled, the directives won't have any effect). " – Alan2 Jun 18 '13 at 03:21