I need to be able to access the current element of ng-repeat inside a directive. See the jsfiddle for this: http://jsfiddle.net/terebentina/TVEnN/
I am expecting a hash in the console (like {width: 100, height: 100}) but I am not really sure how to do that.
Any help would be much appreciated.
Here is a fiddle that works ( and outputs what you are expecting).
http://jsfiddle.net/TVEnN/2/
Things to Note about ng-repeat
:
ng-repeat
always creates a NEW SCOPE for each element in the array / object. ng-repeat
. For ex: if you defined ng-repeat = "page in pages"
then the current element is available in the scope as page. If you defined ng-repeat = "(key,value) in object"
both key
and value
are available in this new scope.$index
.ng-repeat
creates a new scope and all scopes inherit from their parent the pages
in the above example is still available in this new scope, which means you could do stuff like $scope.pages.length
if you need to.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With