1

I have a directive that is working fine in Chrome, but in IE9 it renders '{{myappInitials.IconColor}' into the HTML:

<tr ng-repeat="person in data.people">
    <td class="text-left">
       <div myapp-initials="person" ></div>
    </td>
</tr>

The directive:

angular.module('myapp.directives', [])
    .directive('myappInitials', function () {
       return {
          restrict: 'A',
          template: "<div style='background-color:{{myappInitials.IconColor}}' class='userIconMedium'>{{myappInitials.Firstname.charAt(0) + ' ' + myappInitials.Surname.charAt(0)}}</div>",
          scope: {
             myappInitials: "="
          }
  };
});

There is a Plunker here to check.

Is this an Angular bug?

4
  • 1
    I cant really test this on IE9 but Have you tried using ng-class ? Commented May 18, 2014 at 8:10
  • 1
    You can also use ng-style Commented May 18, 2014 at 8:25
  • It doesn't make any difference changing the style tag to ng-style in this example. Commented May 18, 2014 at 16:47
  • replace style with ng-attr-style Commented Apr 1, 2015 at 16:57

1 Answer 1

4

IE (including 11) does not support interpolation in style attributes. You must use ngStyle for that, e.g ng-style="{'background-color': myAppInitials.IconColor}"

https://docs.angularjs.org/guide/ie

This is my working solution, though I'd prefer to include the ng-style element within the template of the directive but I am not yet sure whether this is possible:

<tr ng-repeat="person in data.people">
    <td class="text-left">
       <div ng-style="{'background-color':person.IconColor}" class="userIconMedium" myapp-initials="person"></div>
    </td>
</tr>

The directive:

angular.module('myapp.directives', [])
    .directive('myappInitials', function () {
       return {
          restrict: 'A',
          template: "{{myappInitials.Firstname.charAt(0) + ' ' + myappInitials.Surname.charAt(0)}}",
          scope: {
             myappInitials: "="
          }
};
 });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.