Question

I have a div element and a ng-click event handler attached to it. something like

<div ng-controller='controller' ng-click='handle($event)'>
  <div ng-repeat='foo in foos'>{{foo.name}}</div>
</div>

When user clicks on foo.name, i could capture the event but it seems that i couldn't access the isolated scope created by ng-repeat.

I try following this path getEvent->getTarget->getBindedScope.

actual codes are something like

var a = $($event.target)
var ac = a.scope();

but when i do

console.log(ac);

the stuff logged out is "undefined".

What i wish to achieve here is accessing that scope and get other stuff out. Such as foo.id or foo.someproperty

Lots of appreciation for the help in advance.

PS:I know this is not the angularjs way, but I wish to achieve due to some other reasons.

PS2: $event.target is tried. logging result is something like

Était-ce utile?

La solution

I'm not exactly clear on what you are trying to do (I don't use jQuery that much, and not with AngularJS), but I get that you want access to the foo object (or other aspects of that item's scope) inside the ngRepeat from the ngClick method.

Could you not do this instead?

<div ng-controller='controller'>
  <div ng-repeat='foo in foos' ng-click='$parent.handle($event)'>{{foo.name}}</div>
</div>

That way you are calling the parent controller's handle() method (due to the $parent prefix) from within the ngRepeat item's isolated scope.

Let me know if that helps.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top