2

I have problem with IE only when I try to render a property into style attribute.

Html:

<span style="background-color: {{ color }}">{{ color }}</span>

var myApp = angular.module('myApp',[]);

//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});

function MyCtrl($scope) {
    $scope.name = 'Superhero';
    $scope.color = '#00ffff'
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp">
  <div ng-controller="MyCtrl">
    <span style="background:{{color}}">Hello, {{name}}!</span>
  </div>
</div>

fiddle

If your solution will be using ngStyle I will be glad to example of code that use the variable $scope.color. That's mean that when the $scope.color will be change I want that the background will change too.

2
  • When you say IE please also post the version. Commented Nov 6, 2014 at 9:32
  • I was checked at 11 version, but I think that is not depends on version. Commented Nov 6, 2014 at 9:35

2 Answers 2

2

You can use ngStyle directive:

<span ng-style="{'background-color': color}">Hello, {{name}}!</span>

Where color is your $scope.color

Sign up to request clarification or add additional context in comments.

Comments

2

Try to use

ng-style="{'background': (color)}"

http://jsfiddle.net/rg6r35sq/3/

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.