0

Im trying to write some fairly simple JS.

I have a rang of angular controllers defined on my HTML pages, e.g:

<div ng-controller="Ctrl1">

    // My code

</div>

How would i go about writing some vanilla JS/jQuery on page load, to detect if 'ng-controller' exists?

Thanks

1
  • Because, what i want to achieve is that if ng-controller exists, then angular.bootstrap(document,['myApp']);.... Not all my pages are/need to load Angular (not the best solution or correct use of ANgular i know) Commented Jul 3, 2014 at 8:21

1 Answer 1

1

You can use a simple attribute querySelector:

if(document.querySelector("[ng-controller]")) {
    // ng-controller tag exists
}
Sign up to request clarification or add additional context in comments.

Comments

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.