Question

is it possible to avoid repeating the code here by replacing the ng-switch by ng-class.

<li ng-repeat="el in elm.required">
    <span ng-switch on="el.type" >
        <i class="icon-file" ng-switch-when="upload" tooltip="{{el.name}}" ng-class="{'muted':!el.completed}"></i>
        <i class="icon-check" ng-switch-when="checkbox" tooltip="{{el.name}}" ng-class="{'muted':!el.completed}"></i>
        <i class="icon-calendar" ng-switch-when="date" tooltip="{{el.name}}" ng-class="{'muted':!el.completed}"></i>
        <i class="icon-pencil" ng-switch-when="text" tooltip="{{el.name}}" ng-class="{'muted':!el.completed}"></i>
        <i class="icon-envelope" ng-switch-when="email" tooltip="{{el.name}}" ng-class="{'muted':!el.completed}"></i>
    </span>
</li>

with something like this (not working, because there are two ng-class instructions) :

<li ng-repeat="el in elm.required">
    <i tooltip="{{el.name}}" ng-class="{upload:'icon\-file', checkbox:'icon\-check', 'date':'icon\-calendar', text:'icon\-pencil', 'email':'icon\-envelope'}[el.type]" ng-class="{'muted':!el.completed}" ></i>
</li>
Was it helpful?

Solution

Instead of doing an Angular version you could just create a css classes of .upload .checkbox etc.. that map to the icon-*

<li ng-repeat="el in elm.required">
    <i tooltip="{{el.name}}" class="{{el.type}}" ng-class="{'muted':!el.completed}" ></i>
</li>

Example on jsfiddle

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top