I am creating an angular directive that shortens a paragraph or div if it contains more than a certain number of characters (e.g. 115).
I was not able to find anything that worked for me, I saw http://dotdotdot.frebsite.nl/ and some people worked, but I am trying to do this using the angular directive, not JQuery.
If there is any help someone can offer, it would be highly appreciated, I am essentially excluded from the ideas.
This is a way to customize my view:
<div class="Description" <div class="Content"> <div data-ng-bind-html="item.Description"></div> </div>
I initially did this by simply making it like jquery, but just jquery and angular are not recommended
$(function () { var maxHeight = 115; var moretext = Localization.Shared.InstitutionProfileStrings.ShowMore(); var lesstext = Localization.Shared.InstitutionProfileStrings.ShowLess(); $('.__Description').each(function () { var content = $(this).find(".__Content"); var anchor = $(this).find(".morelink"); if ($(content).height() > maxHeight) { $(this).addClass("less"); $(anchor).html(moretext); $(anchor).show(); } else { $(anchor).hide(); } }); $(".morelink").click(function (e) { e.preventDefault(); var parent = this.parentElement; if ($(parent).hasClass("less")) { $(parent).removeClass("less"); $(this).html(lesstext); $(parent).addClass("more"); } else if ($(parent).hasClass("more")) { $(parent).removeClass("more"); $(this).html(moretext); $(parent).addClass("less"); } return false; }); });
source share