Answer the question
In order to leave comments, you need to log in
How to create DI as a factory?
I have two custom classes:
export class DocumentBlock extends DocumentCustomBlock {}
export class DepartamentBlock extends DocumentCustomBlock {}
class CustomBlockModel {
constructor(public type: string, id: number)
}
export const documentCustomBlockFactory = (httpClient: HttpClient, model: CustomBlockModel) => {
try {
switch (model.type) {
case 'doc_num_date_block':
return new DocNumDateBlock(httpClient, model);
case 'dep_block':
return new DepartamentBlock(httpClient, model);
default:
throw new Error('Undefined block type!');
}
} catch (e) {
console.log('ERROR: ' + e);
}
};
MatDialog
. DocumentList
I get the response data as an array: this.documents = response;
let model = new CustomBlockModel(this.documents[0]);
matDialog.config.data = documentCustomBlockFactory(this.httpClient, model);
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