component-party.dev icon indicating copy to clipboard operation
component-party.dev copied to clipboard

Added Context snippet for Angular

Open raghavkanwal opened this issue 2 years ago • 1 comments

Context Composition is a bit tricky with Angular, I've used the in-built ngTemplateOutletContext to perform this. More info here

raghavkanwal avatar Jul 29 '23 09:07 raghavkanwal

In terms of React/SolidJS Context is for avoiding props drilling. Regarding Angular, a parent component could provide a service available in all components below in the DOM tree. Template outlet context won't provide a context below the first-tier child E.g. Parent Tabs

@Component({
...
template: '<app-tabs><app-tab *ngFor="let tab of tabs" [tab]=tab /></app-tabs>',
providers: [LocalTabsService]
})
export class TabsComponent {...}

Tab: <div>...<app-subtab /></div>

Subtab component

export class SubtabComponent {
 localTabs = inject(LocalTabsService); // available here without Props (inputs) drill
}

samvimes01 avatar Aug 06 '23 11:08 samvimes01