This package has been moved to [@yellowspot/ng-truncate](https://www.npmjs.com/package/@yellowspot/ng-truncate)
npm install ng2-truncateThis project is a Angular 4+ pipe to truncate text to a set of characters or words.
To install this library, run:
``bash`
$ npm install ng2-truncate --save
By default, the pipe will truncate text after 40 characters. You could override this using the first argument:
`TypeScript
import { Component } from '@angular/core';
import { TruncateModule } from 'ng2-truncate';
@Component({
selector: 'my-component',
template: '
{{ "123456789" | truncate : 3 }}
'}
@NgModule({
imports: [ TruncateModule ],
declarations: [ MyComponent ]
})
export class MyApp { }
`
This will produce the following html
` 123…HTML`
There is a second argument which allow to override the suffix used:
` {{ "123456789" | truncate : 3 : "xxx" }}TypeScript`
@Component({
...
template: '
...
})
This will produce the following html
` 123xxxHTML`
You can also truncate left side by using negative limit
` {{ "123456789" | truncate : -4 : "…" }}TypeScript`
@Component({
...
template: '
...
})
This will produce the following html
` …6789HTML`
Using TruncateModule also enable truncating by words
`TypeScript
import { Component } from '@angular/core';
import { TruncateModule } from 'ng2-truncate';
@Component({
selector: 'my-component',
template: '
{{ "1234 567 89" | words : 2 }}
'}
@NgModule({
imports: [ TruncateModule ],
declarations: [ MyComponent ]
})
export class MyApp { }
`
This will produce the following html
` 1234 567…HTML`
This pipe has also a second parameter to override the suffix used
Check out the Live demo
...Or modify on Plunker here
...Or clone the demo app built using angular-cli: https://github.com/yellowspot/ng2-truncate-demo
To generate all .js, .js.map and *.d.ts files:
`bash`
$ npm run tsc
To lint all *.ts files:
`bash`
$ npm run lint
To execute all test via via Karma:
`bash``
$ npm run test