How can i declare an observable and how to add data to it in angular2 ?
I have 5 hours trying to figure out how to do it.
I tryed this
this.products : Observable<array>;
var object = {"item":item};
this.products.subscribe(object)
everything i tryed throws me an error
I want to use it because i have an array of objects that is changing frequently and in the template the ngFor is not changing the values.
Any help?
http://pastebin.com/1cFXJHHk Here is what i try to do
@pixelbits provided a great answer describing the way to use raw observables.
But I think you misunderstood what observables and reactive programming are. You could have a look at this great introduction to start:
The subscribe method of obersables allows to register callbacks for notifications:
Of course you can leverage events to add an element in a list but I'm not sure that it's your use case:
var someList = [];
let observable = (...)
observable.subscribe(data => {
someList.push(data);
});
This is particularly useful for event-based tools / technologies like WebSockets, Firebase, ... The observable above would be linked on them. This answer could give you more details on how to implement this with Firebase:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With