개발/angular

[Pipe] List 나누기 (자르기), 문자열 나누기

지승준 2018. 2. 13. 14:56

https://angular.io/api/common/SlicePipe


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// List Example
@Component({
  selector: 'slice-list-pipe',
  template: `<ul>
    <li *ngFor="let i of collection | slice:1:3">{{i}}</li>
  </ul>`
})
export class SlicePipeListComponent {
  collection: string[] = ['a''b''c''d'];
}
 
 
 
// String Examples
@Component({
  selector: 'slice-string-pipe',
  template: `<div>
    <p>{{str}}[0:4]: '{{str | slice:0:4}}' - output is expected to be 'abcd'</p>
    <p>{{str}}[4:0]: '{{str | slice:4:0}}' - output is expected to be ''</p>
    <p>{{str}}[-4]: '{{str | slice:-4}}' - output is expected to be 'ghij'</p>
    <p>{{str}}[-4:-2]: '{{str | slice:-4:-2}}' - output is expected to be 'gh'</p>
    <p>{{str}}[-100]: '{{str | slice:-100}}' - output is expected to be 'abcdefghij'</p>
    <p>{{str}}[100]: '{{str | slice:100}}' - output is expected to be ''</p>
  </div>`
})
export class SlicePipeStringComponent {
  str: string = 'abcdefghij';
}
cs


'개발 > angular' 카테고리의 다른 글

angular 기본 명령어 모음  (0) 2019.05.16
[Angular] 기본 명령어  (0) 2018.04.23
[Pipe] 날짜 타입 변경  (0) 2018.02.13
[Pipe] 콤마처리  (0) 2018.02.13
[Angular] 사이즈 조절 이벤트  (0) 2018.02.13