Angular 4 Observables

Angular 4 Observables
The result of the Http.get method is an object, which is an example of an observable. Observables are part of a library called Reactive Extensions, produced by Microsoft, which is used by Angular to connect different parts of the appplication. [Essential Angular for ASP.NET Core MVC by Adam Freeman]

Below are Angular 4 Observables questions and answers for your practice.

1. You import Observable from rxjs/observable to be used within a component. Once you have it imported, you can create an observable object by using the following syntax, where 'vname' is an observable name:



2. Observables allow you to watch values for changes over time and also Observables can have multiple values over time.

A) True
B) False

3. We can subscribe to an observable using the . . . . . . . . The benefit of this is that Angular deals with your subscription during the lifecycle of a component. Angular will automatically subscribe and unsubscribe for you.

A) sync pipe
B) async var
C) async pipe
D) syn var

4. To use observables, Angular uses a third-party library called . . . . . . .

A) ng2-bootstrap
B) angular-cli
C) numeral
D) Reactive Extensions (RxJS)

5. Promises are more advanced than Observables.

A) True
B) False

6. Calls of the next actually deliver the data to it’s subscribers. During observable execution there can be an infinite calls to the observer.next(), however when . . . . . . . is called, the execution stops and no more data will be delivered to the subscribers.

A) observer.error()
B) observer.start()
C) observer.end()
D) observer.complete()

7. We subscribe to the observable ourselves using the actual . . . . . . method. The downside is that you have to manage the subscription yourself.

A) subscribe()
B) subs()
C) subscribed()
D) None of above

8. Observables help you manage . . . . . . . . data.

A) synchronous
B) asynchronous
C) Both asynchronous & synchronous
D) None of above

9. When you have a finite sequence, usually you don’t need to unsubscribe, for example when using the . . . . . . . .

A) finally()
B) date observable
C) HTTP service
D) timer observable

10. When you subscribe to an observer, each call of subscribe() will trigger it’s own independent setup for that given observable. Subscribe calls are shared among multiple subscribers to the same observable.

A) True
B) False

Answers