Angular2 trying to slice string object using SlicePipe in template

Karthigeyan Vellasamy picture Karthigeyan Vellasamy · Jun 1, 2016 · Viewed 7.3k times · Source

Ref : https://angular.io/docs/js/latest/api/common/SlicePipe-class.html. Trying to slice first 20 characters of a string object.

Tried :

<p>{{item.description | slice:0:20}}...</p>

and

<p>{{item.description}}[0:20]: '{{item.description | slice:0:20}}'</p>

Here item.description is of type String

export class Details {
  description: string; 
}

@Component({
  selector: 'editor'
})
export class AppComponent implements OnInit {
  item: details = <Details>{};
}

Note : I am getting value for description in my template using {{item.description}} but when i slice it says

Invalid argument 'undefined' for pipe 'SlicePipe'

Any help would be great.

Answer

G&#252;nter Z&#246;chbauer picture Günter Zöchbauer · Jun 1, 2016

This seems to be a known issue https://github.com/angular/angular/pull/7152

It seems to have been fixed recently but not yet shipped.