Substring with limitTo

I want to limit the size of a string in the page, so I tried this:

  <ion-list inset>
    <ion-item *ngFor="let m of messages">
      {{m.content | limitTo:30}}

But it is giving this error:

EXCEPTION: Error: Uncaught (in promise): Template parse errors:
The pipe ‘limitTo’ could not be found ("

[ERROR ->] {{m.subject}} {{m.content | limitTo:30}} "): MessageListPage@18:41

That error message sounds to me like you haven’t declared the limitTo pipe in the component that’s trying to use it.

Angular 2 pipes were not working for me in Ionic 2. I had to include below script in index.html to get it working.

<script src=""></script>

create a pipe like ionic g pipes max and after paste this code
import { Injectable, Pipe } from ‘@angular/core’;

Generated class for the Max pipe.

See for more info on
Angular 2 Pipes.
name: ‘max’
export class Max {
transform(val, args) {
if (val.length > 80){
return val.substring(0, 80)+’…’;
return val;

after this, import it in your page like :
import {Max} from ‘…/…/pipes/max’;
and make it like a pipes
pipes : [Max]
and in your html file
{{ |max:80}}

use slice ,limitTo does not work anymore

{{m.content | slice:0:30}}


I want to add 3 dots after slicing text. like this: My long text …
What is the solution using slice?

You’re right that’s the answer. Thanks :smiley: