I would like to create an Angular JS directive to check the length of a string, if it is too long to shorten it using a Filter, and show an Angular-UI popover on mouseover.
Where in the directive should I be placing the functionality to get this to work (link, template or compile)?
The view:
<div myapp-shorten="project">{{project.Description}}</div>
Here are my first attempts at the directive so far:
angular.module('myapp.directives', [])
.directive('myappShorten', function () {
function link(scope, element, attrs) {
var outputText = "";
if (myappShorten.Description.length > 20) {
outputText += "<div popover='{{myappShorten.Description}}' popover-trigger='mouseenter'>" +
"{{myappShorten.Description | cut:true:20:' ...'}}</div>";
} else {
outputText += "<div>{{myappShorten.Description}}</div>";
}
element.text(outputText);
}
return {
link: link,
scope: {
myappShorten: "="
}
};
});