I'm currently developing an angular directive (element) that will apply a specific transformation to the text it contains.
Check out the code for the directive below:
module.directive('myDir', function() {
return {
restrict: 'E',
link: function(scope, elem, attrs) {
console.log(elem.text());
},
};
});
At this moment, I've only included a console.log command to ensure that the expected text is being captured.
When using the directive with plain text like in the example below, everything works correctly:
<my-dir>Hello World!</my-dir>
However, if I attempt to use a variable from the scope like so:
<my-dir>{{myMessage}}</my-dir>
The console output displays the variable expression itself rather than its value. While I have an understanding of why this happens, I am uncertain about the correct approach to retrieve and display the actual variable value. The challenge is to ensure that the directive can properly handle text from both types of examples provided.
Any suggestions or ideas?