Greg Greg - 3 months ago 14
AngularJS Question

Get all class names in Angular

I want to check how many

<div class="topology-list">
I have using Angular. At the moment, there are three

I have tried:

angular.element(document.querySelectorAll('.topology-list')).length


This logs
1
(should be 3)

document.querySelectorAll('.topology-list')


Logs
1
too

document.getElementsByClassName('topology-list');


The last one logs an object with the 3 items, but if I add
.length
it logs
1


enter image description here

Answer

Create a directive "your-directive" and put it to the outermost of the HTML

Try the above selections in your directive and all of them should give the correct result.

<body ng-app="yourAppName">
  <div your-directive>
    <!-- Here your all controllers are loaded-->
  </div>
</body>
Comments