I have 2 directives, one that displays a list of objects, and other one that adds objects to that list. The problem that I have is that the list are tied to another elements list this way:
Main code:
<!--main code -->
<div>
<ul>
<li>
<element-a></element-a>
</li>
<li>
<element-a></element-a>
</li>
<li>
<element-a></element-a>
</li>
<li>
<element-a></element-a>
</li>
</ul>
</div>
Element A template
<!-- element-a template -->
<ul>
<li>
<my-element-list></my-element-list>
</li>
<li>
<my-element-list></my-element-list>
</li>
<li>
<my-element-list></my-element-list>
</li>
<li>
<my-element-list></my-element-list>
</li>
</ul>
My List Template:
<!-- my-element-list template -->
<button type="button" data-ng-click="addElement()">Add</button>
<ul>
<li>
my element data
</li>
<li>
my element data
</li>
<li>
my element data
</li>
</ul>
I'm new to angular, but I don't want to have the add directive on each list, as that would have a lot of not needed code added to the html. Also the add is a directive that has a template, etc, that is suppossed to show a modal dialog which will request the element data.
Is this the correct approach for doing this?
How can I get the add modal dialog displayed when the add button is clicked?
I tried with $broadcast
and $emit
, but the add directive is not a parent/child of the element list.