2

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.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
Karthigeyan Vellasamy
  • 2,038
  • 6
  • 33
  • 50

1 Answers1

1

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.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • Is there any other way to slice a string. I am trying to do paragraph Read more functionality(can be done on css) i am trying on angular2. Any info on stable release of Angular2. – Karthigeyan Vellasamy Jun 01 '16 at 10:02
  • 1
    You could just create your own slice pipe. The link above contains the source including the fix (it's just a few lines of cod). It's just not yet included in the shipped Angular versions. – Günter Zöchbauer Jun 01 '16 at 10:05