Error when using limitTo as a filter in ionic 2


I have a problem and I want to limit the number of letters that a property of an object represents using limitTo , I get an error


Error: Uncaught (in promise): Error: Template parse errors: The pipe   'limitTo' could not be found ("click)=" openCart () ">

     {{[ERROR - >] producto.description | limitTo: 50}}


<p class=" description">{{ producto.description | limitTo: 50 }}</p>


productos.description ="Product Description este 
      es mi texto describiendo las caracteristicas completas del 
      articulo, tales como: peso, tamaño, color, etc.";

See documentation - > link

asked by Daniel Enrique Rodriguez Caste 23.06.2017 в 19:25

1 answer


I make this answer based on your comment:

In angular 2, the Pipe filter no longer exists, therefore, you need a custom Pipe (I hope you do not mind, I made some changes to your code):


import { Pipe, PipeTransform } from '@angular/core'; 
@Pipe({ name: 'miLimitTo' }) 

export class LimitToPipe implements PipeTransform {
  transform(value: string, limite: number, desde: number = 0): string { 
      return (value.length > limite)? value.substring(desde, limite) + '...': value.substring(desde, limite); 


import { LimitToPipe } from '../pipes/miPipes'
  imports: [ BrowserModule ],
  declarations: [ App, LimitToPipe ],
  bootstrap: [ App ],
  providers: [],
  exports: [LimitToPipe]


<h2>{{name | miLimitTo:100:10}}</h2>
<h2>{{name | miLimitTo:100}}</h2>

Functional example in Plunkr: link

Thank you very much @DanielEnriqueRodriguezCaste

answered by 24.06.2017 / 17:35