Questions tagged [angular2-observables]

Angular2 Observables refers to the proposed standard for managing async data that was included in the release of ES7. Observables are used by the TypeScript-based open-source web application framework Angular as an interface to handle multiple types of common async operations, such as with EventEmitter, HTTP, and AJAX requests and responses. Use this tag for questions related to the use of Observables in the second version of the Angular framework.

785 questions
228
votes
4 answers

angular2 style guide - property with dollar sign?

Parent and children communicate via a service example from the official guide on Angular.io makes use of dollar signs in Observable stream names. Notice missionAnnounced$ and missionConfirmed$ in the following example: import { Injectable } from…
gerasalus
  • 6,214
  • 5
  • 35
  • 60
178
votes
6 answers

take(1) vs first()

I found a few implementation of AuthGuards that use take(1). In my project, I used first(). Do both work the same way? import 'rxjs/add/operator/map'; import 'rxjs/add/operator/first'; import { Observable } from 'rxjs/Observable'; import {…
Karuban
  • 2,954
  • 3
  • 14
  • 26
165
votes
6 answers

Subject vs BehaviorSubject vs ReplaySubject in Angular

I've been looking to understand those 3: Subject BehaviorSubject ReplaySubject I would like to use them and know when and why, what are the benefits of using them and although I've read the documentation, watched tutorials and searched google I've…
user6015054
92
votes
12 answers

The pipe 'async' could not be found

I am trying to build a simple blog with Angular 2 and Firebase and I am having issues using async pipe in a component. I get the error in the console. zone.js:344Unhandled Promise rejection: Template parse errors: The pipe 'async' could not be…
80
votes
3 answers

Best way to import Observable from rxjs

In my angular 2 app I have a service that uses the Observable class from the rxjs library. import { Observable } from 'rxjs'; At the moment I am just using Observable so that I can use the toPromise() function. I read in another StackOverflow…
Danoram
  • 6,985
  • 10
  • 45
  • 64
45
votes
5 answers

Observable from

What's the preferred way to create an observable from a button's onclick event using Angular 2? I'm not sure if it's considered best practice to grab the native element from the DOM in the component code (how do I do this?), or if there's some other…
GBa
  • 14,931
  • 15
  • 47
  • 67
44
votes
4 answers

How to pass observable value to @Input() Angular 4

I am new to angular and I have the following situation which is I have a service getAnswers():Observable[]>and two components that are related to each other. online-quote dynamic-form online-quote component calls the service…
AlejoDev
  • 2,536
  • 6
  • 26
  • 54
44
votes
3 answers

angular - using async pipe on observable and bind it to local variable in html
Hi I have a observable user$ with a lot of properties (name, title, address...) component{ user$:Observerable; constructor(private userService:UserService){ this.user$ = this.userService.someMethodReturningObservable$() } } Is there…
Han Che
  • 6,900
  • 16
  • 52
  • 97
42
votes
2 answers

Testing error case with observables in services

Let's say I have a component that subscribes to a service function: export class Component { ... ngOnInit() { this.service.doStuff().subscribe( (data: IData) => { doThings(data); }, …
28
votes
4 answers

How to make nested Observable calls in Angular2

I am having some troubles making nested Observable calls. By that I mean a call to a http service that retrieve a user, then getting the id from the user to make another http call, and finally render the results on screen. 1) HTTP GET 1 : get the…
nuvio
  • 2,443
  • 4
  • 28
  • 56
27
votes
6 answers

Angular2. How can I check if an observable is completed?

In my page there is a button that generates a report. That report needs data that is loaded using a http call to a rest endpoint when the page is loaded, but I do not have a guarantee that they are loaded when the user presses the report button. How…
csm86
  • 407
  • 1
  • 5
  • 18
23
votes
4 answers

Angular2/4 : Refresh Data Realtime

I need to refresh the data in a component page in an interval. Also I need to refresh the data after doing some action. I am using Obeservables in the service so that I can subscribe to when the response is ready. I am pushing the subscriptions to a…
21
votes
6 answers

Angular 2+ and Observables: Can't bind to 'ngModel' since it isn't a known property of 'select'

EDIT: Updated Plunkr: http://plnkr.co/edit/fQ7P9KPjMxb5NAhccYIq?p=preview this part works:
Label: {{ entry.label }}
Value: {{ entry.value }}
but I've problems with the select box, the error…
Lonely
  • 5,174
  • 6
  • 33
  • 67
20
votes
3 answers

Angular 2: Observable / Subscription not triggering

I have done this multiple times in my App. It's simple, it should work... But this time it doesn't. My issue: I am calling a method in a service from a Component A, my Component B is subscribed but doesn't react nor receive anything. subscribe() is…
SrAxi
  • 18,577
  • 10
  • 42
  • 65
18
votes
2 answers

Angular 2 - test for change in route params

I have a component in angular 2 which responds to changes in the route parameters (the component doesn't reload from scratch because we're not moving out of the main route. Here's the component code: export class MyComponent{ ngOnInit() { …
1
2 3
52 53