I'm a bit confused about a situation I have, basically I need to toggle a form with the click of a button, without toggling all the forms on the page.
If I have a structure like this:
<ul>
<li ng-repeat="item in cart">
... lots of elements ...
<button data-toggle data-target="myForm">Toggle form</button>
... some container ...
<!-- deep nested form -->
<form class="myForm"></form>
</li>
</ul>
And this directive:
core.directive('toggle', [function() {
return {
restrict: 'A',
link: function($scope, element, attrs) {
element.on('click', function() {
$('.' + attrs.target).stop().slideToggle(100);
});
}
}
}]);
How do I make it so that the button won't toggle every single form in every repeated element? I somehow need to start from the li that the button resides in and then toggle the form, but exactly how can I do that in an efficient way? I was thinking about passing in an isolated scope to the directive and then use that to somehow traverse down the DOM structure and toggle the form, but it feels like that isn't even possible?
What should I do to solve my problem?