GEspinha GEspinha - 2 months ago 7
AngularJS Question

Get a specific element in AngularJs

I have the following code:

angular.element('div');

which returns an object of all the

div
elements on the page. How can I get the index of a specific
div.one
in this object?

I've tried
indexOf()
, but it doesn't work on objects.

https://jsfiddle.net/quodm9mx/

Answer

You can try

angular.element(document.querySelector('.one'));

var myApp = angular.module('myApp',[]);

myApp.controller('GreetingController', ['$scope', function($scope) {
     console.log($(angular.element(document.querySelector('.one'))).index());                      
      
       console.log(angular.element(document.querySelector('.one')));
}]);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myApp" ng-controller="GreetingController">
    <div></div>
    <div></div>
    <div></div>
    <div class="one"></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
</div>