Answer the question
In order to leave comments, you need to log in
Why is useFactory not working?
{
provide: SETTINGS,
useFactory: appInit,
deps: [DocumentsSettings],
},
export function appInit(settings: DocumentsSettings) {
return () => settings.init();
}
@Injectable()
export class DocumentsSettings implements Settings {
@Injectable()
export class DocumentsSettings implements Settings {
private readonly url = `${environment.apiUrl}/documents`;
constructor(
public filtersRepository: DocumentsFiltersRepository,
public sortingRepository: DocumentsSortingRepository,
private http: HttpClient,
) {}
public init(): Promise<boolean> {
return new Promise((resolve, reject) => {
this.filtersRepository
.init()
.then(() => {
this.load().subscribe((response: ResponseSettings) => {
if (response) {
if (response.filters) {
this.filtersRepository.setResponse(response.filters);
this.filtersRepository.modifyDefault();
}
if (response.sortings) {
this.sortingRepository.setResponse(response.sortings);
this.sortingRepository.modifyDefault();
}
}
this.filtersRepository.filter();
this.sortingRepository.sort();
resolve(true);
});
})
.catch((e) => {
reject(e);
});
});
}
}
constructor(
@Inject(SETTINGS) private settings: Settings) {
console.log(this.settings); // Дает () => settings.init()
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question