File tree 4 files changed +57
-11
lines changed
core/src/change_detection
4 files changed +57
-11
lines changed Original file line number Diff line number Diff line change 13
13
*
14
14
* @usageNotes
15
15
*
16
- * In the following example, `RepeatPipe` repeats a given value a given number of times .
16
+ * In the following example, `TruncatePipe` returns the shortened value with an added ellipses .
17
17
*
18
- * ```ts
19
- * import {Pipe, PipeTransform} from '@angular/core';
18
+ * <code-example path="core/ts/pipes/simple_truncate.ts" header="simple_truncate.ts"></code-example>
20
19
*
21
- * @Pipe ({name: 'repeat'})
22
- * export class RepeatPipe implements PipeTransform {
23
- * transform(value: any, times: number) {
24
- * return value.repeat(times);
25
- * }
26
- * }
27
- * ```
20
+ * Invoking `{{ 'It was the best of times' | truncate }}` in a template will produce `It was...`.
28
21
*
29
- * Invoking `{{ 'ok' | repeat:3 }}` in a template produces `okokok`.
22
+ * In the following example, `TruncatePipe` takes parameters that sets the truncated length and the
23
+ * string to append with.
24
+ *
25
+ * <code-example path="core/ts/pipes/truncate.ts" header="truncate.ts"></code-example>
26
+ *
27
+ * Invoking `{{ 'It was the best of times' | truncate:4:'....' }}` in a template will produce `It
28
+ * was the best....`.
30
29
*
31
30
* @publicApi
32
31
*/
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+
9
+ import { NgModule } from '@angular/core' ;
10
+ import { TruncatePipe as SimpleTruncatePipe } from './simple_truncate' ;
11
+ import { TruncatePipe } from './truncate' ;
12
+
13
+ @NgModule ( { declarations : [ SimpleTruncatePipe , TruncatePipe ] } )
14
+ export class TruncateModule {
15
+ }
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+
9
+ import { Pipe , PipeTransform } from '@angular/core' ;
10
+
11
+ @Pipe ( { name : 'truncate' } )
12
+ export class TruncatePipe implements PipeTransform {
13
+ transform ( value : any ) {
14
+ return value . split ( ' ' ) . slice ( 0 , 2 ) . join ( ' ' ) + '...' ;
15
+ }
16
+ }
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+
9
+ import { Pipe , PipeTransform } from '@angular/core' ;
10
+
11
+ @Pipe ( { name : 'truncate' } )
12
+ export class TruncatePipe implements PipeTransform {
13
+ transform ( value : any , length : number , symbol : string ) {
14
+ return value . split ( ' ' ) . slice ( 0 , length ) . join ( ' ' ) + symbol ;
15
+ }
16
+ }
You can’t perform that action at this time.
0 commit comments