Angular Observable vs Promise: 5 Key Differences You Must Know!

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ต.ค. 2024

ความคิดเห็น • 32

  • @MonsterlessonsAcademy
    @MonsterlessonsAcademy  หลายเดือนก่อน

    WATCH NEXT: Beginner's RxJS Tutorial: Dive Deep with RxJS Crash Course - th-cam.com/video/yJdh1_FbtjU/w-d-xo.htmlsi=qhsqP7Eu3Nd7_hIU

  • @kingsleyetoka2792
    @kingsleyetoka2792 ปีที่แล้ว +4

    An actual interview question. Many thanks for sharing

  • @nnikchikvaidze
    @nnikchikvaidze ปีที่แล้ว +4

    Greetings from country of Georgia, well done! always watching your videos, thank you for good content ! 😊

  • @StasSorochan
    @StasSorochan ปีที่แล้ว +1

    In my stege period they put me in project on Angular. I started to learn it from zero because i have studied React before. Your video helps me understand some things. Thank you. Also i saw what you use vim, so i decided to touch nvim and then it's away we go, nvchad, plugins, lsp and it's been like that for a month now.

  • @Z3rgatul
    @Z3rgatul ปีที่แล้ว +1

    Thanks, this is really confusing for new ppl in angular like me. Now I see advantages for stateless pages, need to learn it more to see advantages for stateful pages.

  • @val-do
    @val-do ปีที่แล้ว +2

    Greetings from Georgia 🇬🇪

  • @Georgii1212
    @Georgii1212 ปีที่แล้ว +1

    Hello! Thanks a lot for the tutorial! Can you please give a bit more details about the last difference you mention : errors. I thought that there was a catch block for errors, in promises ...?

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  ปีที่แล้ว +1

      It's not really a difference. You get errors in catch for promise and you pack either catchError function in observable or you handle an error inside subscription

  • @jluisOlivares
    @jluisOlivares ปีที่แล้ว +1

    Hi, would you please make a video about the new angular signals sharing data between components? Thanks in advance.

  • @thmscq5713
    @thmscq5713 ปีที่แล้ว +1

    but using observables kinda wastes the big potential of await, doesn't it? if we want a synchronous function we have to transform it into a promise each time

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  ปีที่แล้ว +1

      I think you understand it wrong. Await doesn't make your function sync. It just looks sync and every next line with await waits for previous line to be done. But it is still 100% async.
      Regarding your question async await is just sugar for promises. You don't get anything new and it has all the same problems.

  • @chrisb3902
    @chrisb3902 ปีที่แล้ว

    Great explanation and video!

  • @naylagomes1212
    @naylagomes1212 ปีที่แล้ว +1

    aren't promises better for cases where one action needs to wait for another to finish?
    for example, I have method A and B, method A needs to wait for the request inside method B to finish
    I particularly don't like using subscribe on occasions like this, as it makes me put method A inside method B's subscribe so I can wait for it to finish, and sometimes that's not my goal

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  ปีที่แล้ว +3

      No. I don't see any cases where promises are better than rxjs except of the reason that they are available without libs and by using fetch you get promises.
      In RxJS you have concat map where second observable waits for first observable.
      result$ = foo$.concatMap(fooRes => getBarData(fooRes))
      No subscribes needed

  • @Z3rgatul
    @Z3rgatul ปีที่แล้ว +1

    Sorry, I started refactoring promises into observables and quickly realized how wacky my code becomes.
    Just basic example, http request, get response, if one of parameters equals to something, i need to get another http request, get response, and do some filtering with first response.
    example
    async loadData(param1, param2) {
    let data1 = await service.getData1(param1, param2);
    if (!param2) {
    let data2 = await service.getData2();
    data1 = data1.filter(....something with data2....);
    }
    return data1;
    }
    I am feeling like I am writing state machine in observables instead of compiler doing the same for me with promises/await/async.
    All these simple examples from courses work fine, but with something more difficult I feel like observables suck

    • @MonsterlessonsAcademy
      @MonsterlessonsAcademy  ปีที่แล้ว +3

      Well you need to learn rxjs a bit more. Unfortunately I don't help with the code in the comments because it takes a lot of time.
      Check some of my videos on rxjs
      th-cam.com/video/2T3F5TfrYwI/w-d-xo.html
      th-cam.com/video/2zJRw3Cl_Vs/w-d-xo.html
      th-cam.com/video/TFXpoabwBfU/w-d-xo.html

  • @Vaivis
    @Vaivis 3 หลายเดือนก่อน

    Thank you

  • @mehdi-vl5nn
    @mehdi-vl5nn ปีที่แล้ว +1

    Observable = Observer pattern + iterator pattern

  • @aleksandr95
    @aleksandr95 ปีที่แล้ว

    Thx for helpful video 😊

  • @tobalhenriquez8233
    @tobalhenriquez8233 ปีที่แล้ว

    You are the best.

  • @fauzi5848
    @fauzi5848 6 หลายเดือนก่อน

    1:05 what did you say?