0

I am using a table in angular application with below syntax

<table>
             <thead>
                <tr>
                    <th>POS</th>
                </tr>
            </thead>
            <tbody>
                   <td contentEditable="true" [ngStyle]="{'background-color':pinkColor('POS')}" 
                   [textContent]="e.plcOfSrvc"  (input)="e.plcOfSrvc = 
                      $event.target.textContent"/>
            </tbody>
        </table>

i need to limit max char in table cell say like 2 for example we need to limit to 2 chars like "OH" or "IH" not "OHB".

sandeep
  • 35
  • 1
  • 9
  • Does this answer your question? [How to truncate text in Angular2?](https://stackoverflow.com/questions/44669340/how-to-truncate-text-in-angular2) – Markus Zeller Oct 07 '22 at 10:18
  • Hi, thanks for your reply i used in this way but it did not helped me [textContent]="e.plcOfSrvc | slice:0:2" – sandeep Oct 07 '22 at 10:39

1 Answers1

0

You can use limitTo but it seems that it have been removed, but there is a slice pipe which does basically the same thing as limitTo and can be used on strings as well as lists.

In your case, a simple {{ item.description | slice:0:2 }} would be sufficient. It also gives you the option of starting your limit at a given starting index, which is interesting. Unless if you want to earn more experience by writing your own pipe, which I advise ;)

<td class="text">
      {{ item.description | slice:0:2}}
</td>