1

My target is to search my notes by Title and truncate Body by a letters or words limit. I don't know if its possible to do that and how. I don't want to mess up with any custom filters , directives etc.

This is a idea of the html:

<section class="notespage" ng-controller="NotesController">
 <h2>Notes list</h2>

 <div>
  Search:
  <input type="text" ng-model="searchText">
 </div>

 <div class="notesleft">
  <div class="notelist">  
   <div ng-repeat="note in notes | filter:searchText | truncate:{body:letterLimit}">
    <div><h3>{{note.title}}</h3></div>
    <div>{{note.body}}</div>
   </div>
  </div>
 </div>
</section>

Where this should be ? In NotesController ?

$scope.letterLimit = 20 ;

1 Answer 1

2

Since you don't want to "mess up" with custom filters etc, you can use the built-in limitTo filter to limit the number of characters displayed as note.body:

$scope.letterLimit = 20;

<div>Search:<input type="search" ng-model="searchText" /></div>
<div ng-repeat="note in notes | filter:searchText">
    <div><h3>{{note.title}}</h3></div>
    <div>{{note.body | limitTo:letterLimit}}</div>
<div>

See, also, this short demo.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.