I have a table news:
export class News{
id: string;
name: string;
text: string;
admin: boolean;
users: Users;
}
I have a method which returns the list of news.ts:
news: News[];
pageNews: News[];
getNews(): void {
//let MaxLength = 5;
this.newsService.getnews().subscribe(res => {
this.news= res;
this.pageNews= this.news.slice(0, 10);
}
);}
in news.html:
<table class="table table-bordered table-striped" style="border: none;">
<thead>
<tr>
<td class="title-column">Id</td>
<td class="title-column">Name</td>
<td class="title-column">Text</td>
</tr>
</thead>
<tr *ngFor="let u of pageNews">
<td class="row-mid">{{u.id}}</td>
<td class="row-mid">{{u.name}}</td>
<td class="row-mid">{{u.text}}</td>
</tr>
</table>
but when the name or text are too long, my table overflows, so, I would like to truncate my name and my text when it exceeds 20 characters and put points afterwards. Example:
string s = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
result = 'aaaaaaaa...'
I try in my news.ts but it does'nt work
news: News[];
pageNews: News[];
getNews(): void {
//let MaxLength = 5;
this.newsService.getnews().subscribe(res => {
this.news= res.filter(e=>{e.name= e.name.substring(0,20) + '...',
e.text= e.text.substring(0,20) + '...';});
this.pageNews= this.news.slice(0, 10);
}
);}