I am working on an Angular 1 app and I need to call different directives based on a value in a ng-repeat loop. I am using ng-if so far which renders that directive if it matches the condition but what I am thinking is that if I got 100 directives after some time, then I will be using 100 ng-ifs and I am thinking there must be some better solution for this.
Here's some of my code
Template which calls the directive
<render-directive ng-if="data.length !== 0" data="data"></render-directive>
Template of renderDirective
<div ng-repeat="element in data">
<div ng-if="element.item === 'motor'">
<render-motor motor-id="element.id" name="element.item"
checked="element.params.switch"></render-motor>
</div>
<div ng-if="element.item === 'adc'">
<render-adc adc-id="element.id" name="element.item"></render-adc>
</div>
</div>
For sake of simplicity, I've only shown two directives but in real I am already calling more than 10 directives and it can go upto 100 in future.
So does anyone can tell me a better way to do this, where I won't have to use ng-if for every directive?
Please do let me know if I haven't cleared something in question.
UPDTAE
For clearing what I am exactly looking for, I have an array which has 'item' propery and according to that property I want to call a directive. So for eg,
- for item = "motor", I want to call motorDirective
- for item = "switch", I want to call switchDirective
- for item = "led", I want to call ledDirective
and so on.
ng-ifdirectives.