How can I create a custom angular directive to show and hide child element when clicked on neighbour element?
So when clicked on the h2 I want to display custom_elem using a custom directives.
Remember that the div is repeating with ngFor. So the instance of div should only show the child element (custom_elem) when clicked on h2 while the child element(custom_elem) of other instances of the div stay hidden .
<div *ngFor="let item of items">
<h2 (click)="" >item.name</h2> // if I click here it will pass show or hide (true or false) values to the directive.
<custom_elem>somedata</custom_elem> //show these (then the directive will handle the display properties of these child elements)
<div>
see that I don't; want to dynamically add anything new.
The ngfor is already looping(at the beginning) itself. Only What I want is that I just want to toggle the display of the (custom_elem) when I click on the h2 (using a custom directive).
We want a custom directive. so that when I click on the h2 I can pass true or false values to the directive & then the directive will handle the display properties of (custom_elem)
this way the show or hide properties are bound locally with the instance of the corresponding element. & not connected to the component.ts.
UPDATE div is repeating with ngFor. h2 will be always visible. when clicked on h2, custom_element display turns on and off.
This is the final result needed. When I click on h2 I want to display the corresponding custom_elem (which is neighbour of h2).