Oam Psy
Oam Psy

Reputation: 8663

How to detect if ng-controller exists on a HTML page

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

Upvotes: 0

Views: 104

Answers (1)

CodingIntrigue
CodingIntrigue

Reputation: 78535

You can use a simple attribute querySelector:

if(document.querySelector("[ng-controller]")) {
    // ng-controller tag exists
}

Upvotes: 1

Related Questions