#71 RxJS of() & from() Operator | Understanding Observables & RxJS | A Complete Angular Course

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

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

  • @Kindness-od6fj
    @Kindness-od6fj Год назад +11

    Hi sir, one doubt
    When converting a Promise into an Observable, we are using from() .
    Output of from() operator should be like :
    10
    20
    30
    40
    50
    but it is emitting like a whole array 10,20,30,40,50 (12:19 of video), which is the pattern of the of() operator
    So, we can say that while converting a Promise using from() , it will not iterate .
    Output will be like of the of() , not like of the from() operator ?

    • @subhajitadhikary155
      @subhajitadhikary155 11 месяцев назад +1

      Also having this doubt. Manoj sir, can you please have a look?

    • @BusTech-yw9uk
      @BusTech-yw9uk 6 месяцев назад +1

      Same doubt

  • @Raja-qj3vp
    @Raja-qj3vp 5 месяцев назад +3

    (The below answer is not my own, like many i also can't understand last example of the video which involved promise, so i asked the doubt in chatgpt and it provided the below answer, pasting it here so it may help people like me who didn't understand)
    In the context of the example provided, "resolve" is a method used to create a promise that is already resolved with a specified value. This is a feature of the Promise object in JavaScript.
    When using the from operator in RxJS to convert a promise to an observable, it behaves differently based on the type of the promise's resolved value.
    Here's a breakdown of the behavior:
    Promise that "resolves" to a single value: The from operator will emit that single value.
    Promise that "resolves" to an array: The from operator will emit the entire array as a single value, not individual elements.
    If we want to iterate over the elements of the array and emit each element separately, we need to first convert the promise to an observable, and then use the mergeMap operator to further process the emitted array into individual elements.
    example:
    import { from } from 'rxjs';
    import { mergeMap } from 'rxjs/operators';
    // A promise that resolves to an array
    const promise = Promise.resolve([10, 20, 30]);
    // Convert the promise to an observable and emit each element separately
    const observable = from(promise).pipe(
    mergeMap(array => from(array))
    );
    observable.subscribe(value => console.log(value));
    output:
    10
    20
    30

  • @pragmaticcoder6910
    @pragmaticcoder6910 Год назад +7

    Sir,
    Please do NgRx series as well. Will be really helpful for career growth

  • @sagarvyas5527
    @sagarvyas5527 17 дней назад

    Like for java durga sir is best and for angular you r the best rq

  • @peymanesmaili7191
    @peymanesmaili7191 11 месяцев назад

    i have a question . when we convert promise to observable with from operator . from operator should oprated array in promis but it didnt? and we see all data without streaming it ?why

  • @Manojkumar-vl6hi
    @Manojkumar-vl6hi 6 месяцев назад

    of operator will emit data one after other or, simultaneously. had confusion since in last lecture we kept time out to show some diff in time. so i thought you kept that since next is an observer.next is async function.