반응형
사용자 지정 파이프 공급자 없음 - 각도 4
각진 십진법 파이프를 차례로 사용하는 사용자 지정 십진법 파이프가 있습니다.이 파이프는 공유 모듈의 일부입니다.기능 모듈에서 사용하고 있으며 응용 프로그램을 실행할 때 공급자 오류가 발생하지 않습니다.
오타가 있으면 무시해 주세요.
./src/src/custom.pipe.ts
import { DecimalPipe } from '@angular/common';
..
@Pipe({
name: 'customDecimalPipe'
})
...
export class CustomPipe {
constructor(public decimalPipe: DecimalPipe) {}
transform(value: any, format: any) {
...
}
./syslog/shared.syslog.
import { CustomPipe } from '../pipes/custom.pipe';
...
@NgModule({
imports: [ .. ],
declarations: [ CustomPipe ],
exports: [ CustomPipe ]
})
export class SharedModule { }
나는 구성 요소 중 하나에 사용자 정의 파이프를 주입하고 변환된 값을 얻기 위해 변환 방법을 호출합니다.공유 모듈을 기능 모듈로 가져옵니다.
파이프를 사용하려면transform()
구성 요소의 메서드, 추가도 필요합니다.CustomPipe
모듈 공급자에게:
import { CustomPipe } from '../pipes/custom.pipe';
...
@NgModule({
imports: [ .. ],
declarations: [ CustomPipe ],
exports: [ CustomPipe ],
providers: [ CustomPipe ]
})
export class SharedModule { }
추가하는 것을 제외하고는CustomPipe
모듈의 공급자 목록에 구성 요소의 공급자를 추가하는 방법이 있습니다.이는 사용자 정의 파이프가 일부 구성 요소에서만 사용되는 경우에 유용할 수 있습니다.
import { CustomPipe } from '../pipes/custom.pipe';
...
@Component({
templateUrl: './some.component.html',
...
providers: [CustomPipe]
})
export class SomeComponent{
...
}
이게 도움이 되길 바랍니다.
파이프를 Injectable로 설정할 수도 있습니다(CLI를 사용하여 만든 서비스와 동일한 방법).
import { Injectable, Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'customDecimalPipe'
})
@Injectable({
providedIn: 'root'
})
export class CustomPipe extends PipeTransform {
...
}
언급URL : https://stackoverflow.com/questions/46299952/no-provider-for-custompipe-angular-4
반응형
'programing' 카테고리의 다른 글
PowerShell에서 "<" 입력 리디렉션이 구현되지 않는 이유는 무엇입니까? (0) | 2023.07.25 |
---|---|
C의 이중 부정 : 0/1을 반환하는 것이 보장됩니까? (0) | 2023.07.25 |
jQuery를 사용하여 첫 번째 "n"개 항목 선택 (0) | 2023.07.25 |
산점도:산란을 위한 lib 색상 막대 (0) | 2023.07.25 |
AJAX 요청의 내용 유형 및 데이터 유형은 무엇입니까? (0) | 2023.07.25 |