각도로 서비스에 대한 질문이 있습니다.각도로 간단한 유틸리티 기능을 사용하는 서비스
의 난이 간단한 서비스를 가정 해 봅시다 :
@Injectable()
export class ApplicationUtilsService {
constructor() {
}
checkIfObjectExistAndGet(map: Map<string, Object>, sectionName: string): Object {
return map.has(sectionName) ? map.get(sectionName) : {};
}
}
왜 그냥 만들어 수출 함수 :
export function checkIfObjectExistAndGet(map: Map<string, Object>, sectionName: string): Object {
return map.has(sectionName) ? map.get(sectionName) : {};
}
내가 원하는 때마다 나는 그것을 가져올 수 있습니다 그 방법 그걸 써. 구성 요소에 테스트를 삽입 할 필요가 없으므로 테스트를 쉽게 작성할 수 있습니다 (서비스를 제공하거나 모의을 만들 필요가 없습니다).
그래서 이러한 유형의 함수가 서비스에 의해 제공되어야하는지 또는 위의 예와 같이 가져오고 가져 오는 것이 좋을지 궁금합니다.
[한번 궁금해 한 번] (http://stackoverflow.com/questions/42350057/is-there-any-point-in-di-for-class-injections) 나 자신도 여전히 명확한 의견이 없습니다. –