0

I want to create an AngularJs directive that will allow me to display a specific icon (from a folder that contains a lot of different icon) for a specific file, for example:

If myFile is an Html file we display icon_html.png, etc.

I saw this answer from Dayan Moreno Leon but he uses a CSS stylesheet to display the specific icon, I was searching something more generic.

Any advice or recommendations are welcome :)

Update, I tried this :

My directive :

myApp.directive("icon", function () {

return {
    template: "<img ng-src='style/icon/files_type_icons_flat/PNG/icon_{{icon}}.png'/>",
    replace: false,
    scope:   true,
    compile: function (tElement, tAttrs) {
        // this is link function
        return function (scope) {
            scope.icon = tAttrs.icon;
        };            
    }
};

});

My view :

<tr ng-repeat="row in entities" >
    <td>
        <div icon="{{row.extension}}"></div> &nbsp;{{row[col.title]}}.{{row.extension}}
    </td>
</tr> 

Nothing worked :(

Many thanks.

Community
  • 1
  • 1
Zween
  • 11
  • 6
  • you can dynamically append image tag in directive. something like this : element.html(""); if(myFile=='html') element.append(""); if(myFile=='doc') element.append(""); – Mansi Parekh Aug 06 '15 at 07:58
  • Thanks for this answer Mansi Parekh, but like I said I search something more generic I have more than 20 type file, so I can't type 20 times "if(myFile==...)". I find this solution : . It's what I was searching but I want it in a directive. – Zween Aug 06 '15 at 08:12
  • Nobody could help me please ? :) – Zween Aug 07 '15 at 07:08

0 Answers0