0

How get index of one of two div tag without i don't using ng-repeat?
I tried this but it didn't work;

<div ng-click="formselect($index)"></div>
<div ng-click="formselect($index)"></div>
7
  • 1
    Are you at least in the context of an ng-repeat? Commented Jan 19, 2017 at 5:32
  • 2
    That's not ng-submit. Commented Jan 19, 2017 at 5:32
  • @Makoto There are four div tag, i want to send index of clicked tag Commented Jan 19, 2017 at 5:36
  • So like <div ng-click="formselect(0)"></div><div ng-click="formselect(1)"></div>...? Commented Jan 19, 2017 at 6:08
  • @Phil i doing as you say already, but i want to get index of tags like jquery Commented Jan 19, 2017 at 6:13

2 Answers 2

2

HTML:

<div ng-click="formselect($event)"></div>
<div ng-click="formselect($event)"></div>

JS:

var formselect = function(te) {
    return Array.prototype.slice.call(document.getElementsByClassName(te.target.className)).indexOf(te.target)
}
Sign up to request clarification or add additional context in comments.

Comments

0

for me this worked

<div ng-click="formselect('0')"></div>
<div ng-click="formselect('1')"></div>

or if you want to load variables from angular js look into this fiddle or refer to the answer provided in the link

1 Comment

I using array now but what i want to learn is to get index of html tags as like on jQuery, with Angular

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.