私のAngularJSテンプレートには、次のようなカスタムHTML構文が含まれています。
<su-label tooltip="{{field.su_documentation}}">{{field.su_name}}</su-label>
私はそれを処理するためのディレクティブを作成しました:
.directive('suLabel', function() {
return {
restrict: 'E',
replace: true,
transclude: true,
scope: {
title: '@tooltip'
},
template: '<label><a href="#" rel="tooltip" title="{{title}}" data-placement="right" ng-transclude></a></label>',
link: function(scope, element, attrs) {
if (attrs.tooltip) {
element.addClass('tooltip-title');
}
},
}
})
を実行すると属性がGoogleChromeのJavaScriptコンソールから表示される場合でも、attrs.tooltip
常にを返す式を除いて、すべてが正常に機能します。undefined
tooltip
console.log(attrs)
なにか提案を?
更新:ソリューションはArtemによって提供されました。これを行うことで構成されました:
link: function(scope, element, attrs) {
attrs.$observe('tooltip', function(value) {
if (value) {
element.addClass('tooltip-title');
}
});
}
AngularJS + stackoverflow = bliss