• Skip to main content
  • Skip to primary sidebar

Web Development Archive

  • Archive
You are here: Home / Other / Summary Pipe

Summary Pipe

ng g p summary --skip-import

Pipe

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'summary',
  standalone: true,
})
export class SummaryPipe implements PipeTransform {
  transform(value: string): string {
    if (!value) {
      return value; // If the input is empty, return it as is
    }

    if (value.length <= 60) {
      return value; // If the input is already 30 characters or less, return it as is
    }

    return value.substring(0, 60) + '...'; // Return the substring of the input with ellipsis
  }
}

Component

import { Component } from '@angular/core';
import { SummaryPipe } from 'src/app/pipes/summary.pipe';

@Component({
  standalone: true,
  imports: [SummaryPipe],
  selector: 'app-pipe',
  templateUrl: './pipe.component.html',
  styleUrls: ['./pipe.component.scss'],
})
export class PipeComponent {
  text =
    'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed a ante auctor, ' +
    'dictum massa in, consectetur massa. Nam est lorem, elementum a blandit id, sagittis ' +
    'eget ante. Sed tempus mauris a massa blandit, id vehicula nibh lobortis. Fusce in ' +
    'accumsan dui. Pellentesque sit amet mi ut lectus sodales lobortis. Nulla lacinia ' +
    'rhoncus egestas. Nam fermentum metus est, at placerat dolor tempus in. ';

}
<p>{{ text | summary }}</p>

Filed Under: Other

About Gabor Flamich

I'm a web developer and designer based in Budapest, Hungary. In recent years, I've documented hundreds of solutions I came across during development. This site is an archive for useful code snippets on WordPress, Genesis Framework and WooCommerce. If You have any questions related to WordPress development, get in touch!

Primary Sidebar

  • angular.io
© 2026 WP Flames - All Right Reserved