I have a semi arbitrary length ng-repeat with a "tag along" element that gets rendered based on some criteria:
<div ng-repeat-start="day in [1,2,3,4,5,6,7] track by $index">my repeat</div>
<div ng-repeat-end ng-if="shouldRender(day)" class="maybe">maybe rendered</div>
What I want to do is set a click event on the repeated element and reference the NEXT SIBLING "maybe rendered" element in order to do some jQuery magic. So what I want to do is add ng-click="getNextMaybe(this)" and process it to find the next sibling .maybe element. So now I have:
<div ng-repeat-start="day in [1,2,3,4,5,6,7] track by $index" ng-click="getNextMaybe(this)">my repeat</div>
<div ng-repeat-end ng-if="shouldRender(day)" class="maybe">maybe rendered</div>
function myCtrl($scope){
$scope.getNextMaybe = function(repeatElem){
var nextMaybe = $(repeatElem).next('.maybe');
}
}
I think I'm sort of confused as to what this is in this instance and how I can turn it into a jQuery object to do my processing.
Thanks!
You can pass $event to your function and look at $event.target to get the element (plnkr):
<button ng-click="onClick($event)">Button</button>
Controller:
$scope.onClick = function(evt) {
console.dir(evt.target);
}
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