唯一のビジュアルエディターとして、CSSスタイルを記述する新しいディレクティブを作成しようとしています。チェックボックスをクリックしてbackground-colorプロパティを透明にしたときに、ディレクティブを更新しようとして立ち往生しています。
これが私の(機能しない)ディレクティブです:
myApp.directive('customstyle', function () {
return {
restrict: 'E',
link: function (scope, element, attrs) {
var bgColor;
scope.$watch(attrs.myTransparent, function (value) {
if (value) {
bgColor = 'transparent';
} else {
bgColor = attrs.myBgcolor;
}
updateStyle();
}, true);
function updateStyle() {
var htmlText = '<style>.' + attrs.myClass + '{';
htmlText += 'background-color: ' + bgColor + ';';
htmlText += "}</style>";
element.replaceWith(htmlText);
}
updateStyle();
}
}
});
およびhtml要素:
<customstyle my-class="examplediv" my-transparent="settings.Window.Transparent" my-bgcolor="settings.Window.BackgroundColor"></customstyle>
これが状況のjsfiddleです:http://jsfiddle.net/psinke/jYQc6/
どんな助けでも大歓迎です。