Is it possible to create a "more.." tag in Angular which will appear if a string shows more than 100 characters (for example)? When you push the link it will show the rest of the characters.
I have been trying to find an example but without any luck.
Thanks in advance.
Edit: -- WORKING!
I have added Don's solution.
This is my bundle/angularjs:
"~/Scripts/angular.js",
"~/Scripts/angular-*",
"~/Scripts/angular.min.js",
"~/Scripts/ng-sortable.js",));
This is my bundle/myapp:
"~/Scripts/EventIndexAngularController.js"));
This is my index.cshtml:
@model IEnumerable<Nybroe.FightPlan.Sql.Model.EventRecord>
@section scripts {
@Scripts.Render("~/bundles/angularjs")
@Scripts.Render("~/bundles/jqueryui")
@Scripts.Render("~/bundles/myapp")
}
@{
ViewBag.Title = "Index";
}
<div class="row">
<hr />
<div ng-app="myApp" ng-controller="MyCtrl">
@foreach (var item2 in Model)
{
<div class="col-md-2 index-box">
<b>@Html.DisplayNameFor(model => model.Details)</b><br />
<p expand-text="100">@Html.DisplayFor(modelItem => item2.Details)</p>
<b>@Html.DisplayNameFor(model => model.Location)</b><br />
<p>@Html.DisplayFor(modelItem => item2.Location)</p>
</div>
}
</div>
</div>
And this is my js file:
var myApp = angular.module('myApp',[]);
myApp.directive('expandText', function() {
return {
restrict: 'A',
link: function(scope, elem, attrs) {
var text = elem.context.innerText;
elem.context.innerText = trunc(attrs.expandText, text, true);
elem.append('<span ng-click="expand();"> more...</span>');
elem.on('click', function() {
elem.context.innerText = text;
});
function trunc(n, text, useWordBoundary) {
var toLong = text.length > n,
s_ = toLong ? text.substr(0, n-1) : text;
s_ = useWordBoundary && toLong ? s_.substr(0, s_.lastIndexOf(' ')) : s_;
return s_;
}
}
}
});
function MyCtrl($scope) {
}