This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
template:` | |
<div popover="popoverOne"> | |
// content | |
</div> | |
<div popover="popoverTwo"> | |
// content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Directive({ | |
selector: '[myDir]' | |
}) | |
export class MyDirDirective { | |
constructor(public template: TemplateRef<any>) { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class CaseOne implements CaseLogicHandler{ | |
key: any = 1; | |
doLogic() { | |
// case logic | |
} | |
} | |
export class CaseTwo implements CaseLogicHandler{ | |
key: any = 2; | |
doLogic() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class CaseOne implements CaseLogicHandler{ | |
key: any = 1; | |
doLogic() { | |
// case logic | |
} | |
} | |
export class CaseTwo implements CaseLogicHandler{ | |
key: any = 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable() | |
export class NastyService { | |
constructor(@Inject(CASE_LOGIC_HANDLER) private caseHandlers: CaseLogicHandler[]) { | |
} | |
doNastyOperation(key: any) { | |
switch (key) { | |
case 1: | |
// logic | |
case 2: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable() | |
export class NastyService { | |
constructor(@Inject(CASE_LOGIC_HANDLER) private caseHandlers: CaseLogicHandler[]) { | |
} | |
doNastyOperation(key: any) { | |
const handler = this.caseHandlers.find(h => h.key === key); | |
if (!handler) throw new Error(`No case handler provided for key: ${key}`); | |
handler.doLogic(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable() | |
export class NastyService { | |
constructor() { | |
} | |
doNastyOperation(key: any) { | |
switch (key) { | |
case 1: | |
// logic | |
case 2: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@NgModule({ | |
providers: [ | |
{provide: CASE_LOGIC_HANDLER, useClass: CaseOne, multi: true}, | |
{provide: CASE_LOGIC_HANDLER, useClass: CaseTwo, multi: true}, | |
// ... | |
] | |
}) | |
export class AppModule { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface CaseLogicHandler { | |
key: any; | |
doLogic(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const LOGIC_HANDLER = new InjectionToken<CaseLogicHandler>('logic.handlers'); |
OlderNewer