Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
#angular #signals #service #matchMedia
To achieve the desired outcome, Iβve opted for an approach that follows this pattern:
β Create a service with a `mediaQuery()` method, which returns an RxJS Observable containing information on whether a specific breakpoint is matched or not.
β Create a property inside the component class (in the example we will call it `isMobile`, since we have only one breakpoint) and bind it the the `mediaQuery()` method previously crafted, but also converting the Observable to a signal.
β Utilize the `NgClass` directive to dynamically apply a class based on the value of the `isMobile` property.
β Article Link
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
π1
π7
BehaviorSubject in Every Angular Service#angular #signals
BehaviorSubject Is a Loaded Gun
It holds state, pushes values, and is hot by default. That means:
β Every new subscriber instantly gets the last value
β You must manually manage .next() calls
β It often leads to imperative logic (e.g. if (...) this._value$.next(...))
β And worst of all?
It gives you a stream, but not semantics.
You canβt know if the value is:
β Cached
β Live from server
β Derived from another value
β Meant to be read-only
β Article Link
Please open Telegram to view this post
VIEW IN TELEGRAM
2π7β€1