The take(1)
approach has a number of advantages over subscribe
:
- Code readability (and elegance).
- The second approach requires that you hold and manage extra variables.
- The second approach will not invoke the complete handler. This is because .take(1) actually create a new observable which potentially yields a single item and completes.
- The second approach will work for the trivial case of taking a single element, but if you need to take more then 1,
take(4)
will stay simple while the second approach will become hard to code.
The 3rd item is the rxjs related one, the others relate to coding style.
Have a look at a sample here.