Challenge
Create a custom directive that dynamically adds the ng-bind attribute, allowing for the use of ng-bind, ng-bind-html, or ng-bind-html-unsafe without needing to manually add it to the template definition throughout.
Illustrative Example
http://jsfiddle.net/nstuart/hUxp7/2/
Directive Bug
angular.module('app').directive('bindTest', [
'$compile',
function ($compile) {
return {
restrict: 'A',
scope: true,
compile: function (tElem, tAttrs) {
if (!tElem.attr('ng-bind')) {
tElem.attr('ng-bind', 'content');
$compile(tElem)
}
return function (scope, elem, attrs) {
console.log('Linking...');
scope.content = "Content!";
};
}
};
}]);
Suggested Fix
Unable to pinpoint a solution. The issue persists despite trying variations with and without additional $compile within the code snippet.
Alternative Approach
To overcome the obstacle, consider including a template value in the directive, albeit resulting in extra div wrapping around the content—a compromise I aim to evade if possible. (Refer to fiddle)
Another Strategy
Visit this fiddle: http://jsfiddle.net/nstuart/hUxp7/4/ (along Dr. Ikarus's recommendation). Temporarily deeming it as an interim fix, as the expectation lingers on the ability to adjust the template pre-linking stage for subsequent detection/application of changes.