Signals for sharing data between components in Angular 16

Поделиться
HTML-код
  • Опубликовано: 4 окт 2024

Комментарии • 9

  • @zorefcode
    @zorefcode  Год назад +3

    stackblitz.com/edit/stackblitz-starters-ug8svk

  • @bb9123f
    @bb9123f Год назад +1

    nice video 👌

  • @hemantdixit4058
    @hemantdixit4058 Год назад +3

    But sharing this counter between conponent can be done without using service?

    • @zorefcode
      @zorefcode  Год назад +1

      these are two independent components and data transfer is done through a service. counter is just an example of data.

    • @SumitN
      @SumitN 9 месяцев назад +1

      @@zorefcode How to make components Change Detection strategy On.Push, and then receive the Signal from service.

  • @SumitN
    @SumitN 9 месяцев назад

    How to implement Change detection On.Push strategy, in this ?

  • @miguelito3056
    @miguelito3056 10 месяцев назад

    This is doable using regular variables in the service component. Why do we need to use signals pls explain thank you

    • @praktycznewskazowki6733
      @praktycznewskazowki6733 10 месяцев назад

      Because using default variable in service will force you to listening this value

    • @avinashsuresh5221
      @avinashsuresh5221 25 дней назад

      One reason I can think of:
      Signals are reactive; variables are not.
      If you have a signal that changes, all dependent signals will update accordingly. If you have a variable that changes, the required changes need to be signaled via an observable. RxJS subjects are most commonly used for this purpose. That way you can send data from one component and receive data in another component by subscribing to the observable variable.
      The important difference is the ability to listen for changes. Variables can't do that, unless they are observables. Signals on the other hand, do exactly that.