I am using custom pipe with ternary operator for *ngFor
, getting errors. Not knowing how to resolve. Please kindly help.
html:
<div *ngFor="let x of y | limitTo: y.limit ? y.length : 10">
truncate.pipe.ts:
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'limitTo'
})
export class TruncatePipe {
transform(value: string, limit:number) : string {
let trail = '...';
return value.length > limit ? limit + trail : value;
}
}
app.module.ts:
import { NgModule } from '@angular/core';
import { TruncatePipe } from './truncate.pipe';
@NgModule({
imports: [
],
declarations: [
TruncatePipe
],
exports: [
]
})
export class AppModule { }
Error:
Cannot find a differ supporting object '10...' of type 'string'. NgFor only supports binding to Iterables such as Arrays`. in html file
"let x of y | limitTo: (y.limit ? y.length : 10)"
– Eliseoy
? – AJT82