0
나는 일부 서비스는Angular 4/5 자동 서비스 제공 업체에서 가능한가요?
// app.module
@NgModule({
providers: [
AuthorsService
],
bootstrap: [
AppComponent
]
})
// authors.service
@Injectable()
export class AuthorsService {
public constructor() {
console.log('service constructor');
}
}
이전 코드와 같은 provices 배열에 추가 할 때 내가 실행 console.log
에 대한 서비스에 뭔가를 할 수처럼 선언?
서비스 시작 나는 서비스 예를 들어 다음과 같은 코드를 피하기 위해 같은 ... 몇 가지 물건을 할 필요가 :
public constructor(
protected authorsService: AuthorsService
) {
}
// only with that console.log is runned
(이유는 묻지 마십시오,이 간단한 예제
for a better use on a library입니다)
Thans for reply ('APP_INITIALIZER'에 대한 예제 : https://github.com/angular/angular/issues/9047#issuecomment-224075188). 그러나 나는 또한 봉사의 측면에서 필요하다 : /. 나는 어떤 해결책도 찾지 못한다. 당신의 해결책이 최고 일 수있다. – pablorsk
서비스에 종속성이없고 질문과 같이 동 기적으로 초기화되는 경우 모듈 생성자에도 서비스를 주입 할 수 있습니다. – estus