Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Repeated style attribute in AngularJS directive

I have an AngularJS directive which specifies replace: true and template: <span style="color: red;"></span>. Whenever I use the directive in my markup, it seems that the contents of the style attribute is repeated in the DOM: <span style="color: red;;color: red;"></span>. Is this a bug in AngularJS, or am I doing something wrong here?

Here is a Plunk that demonstrates the problem: http://plnkr.co/edit/UMhmjGS3XW84d7zctujo

like image 600
vrutberg Avatar asked Apr 21 '26 06:04

vrutberg


1 Answers

I do not know what causes this, but it won't harm to list a possible solution.

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

app.controller('MainCtrl', function($scope) {$scope.style={color:red};);

app.directive('myDirective', function() {
  return {
    replace: true,
    template: '<span ng-style="style" class="my-test-class">something!</span>'
  };
 });

See: ngStyle

like image 90
Wottensprels Avatar answered Apr 22 '26 18:04

Wottensprels



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!