{
  "id": 1365063,
  "title": "The Angular pattern that needs no Provider",
  "url": "https://urgent.news/2026/08/16/the-angular-pattern-that-needs-no-provider",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-08-16T22:00:00.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/playfulprogramming-angular/the-angular-pattern-that-needs-no-provider-2ee4"
  },
  "original_language": "en",
  "account": "When a component needs to know if its host element is currently visible, a commonly used solution is to create a services. However, this approach might be overkill if the logic is local to the component and doesn't represent shared application state. Consider a dashboard widget that uses this information to avoid rendering expensive parts of the template or pause/resume asynchronous processes.\n\nA more efficient solution would be to use a host directive. This encapsulates the functionality without requiring additional provider configuration. By adding the host directive to the component’s metadata, the feature becomes a contextually available signal tied to the component's own lifecycle. While this approach still requires a small amount of metadata boilerplate, it avoids the need for another injectable instance and eliminates the risk of forgetting to declare a provider.",
  "summary": "Services are often the default abstraction for reusable Angular logic. But what if the logic is local to a component, depends on its injection context, and does not represent shared application state? Consider a dashboard widget that knows whether its host element is currently visible: @ Component ({ selector : ' app-dashboard-widget ' , template : ` <p>{{ visible() ? 'Awake' : 'Sleeping' }}</p>…",
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}