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?

2
  • Can you use ng-app instead of manually bootstrapping? If so, just add it to your body element. Commented Jun 17, 2013 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. Commented Jun 17, 2013 at 17:47

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Can you check the following answer to a similar question: stackoverflow.com/questions/16537783/… 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). "

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.