I have a service where I fetch some data form Firebase. That service offers an observable, which I then subscribe to in my component class. When the data is loaded, and sent to the array, the DOM updates with new data, but I need to run some javascript and jQuery code again after the DOM update which I can't figure out how to.
My service method looks like this:
getSubjects() {
return new Observable(observer => {
this.subjectsRef.orderByChild('name').on("value", snapshot => {
var tempArr = [];
snapshot.forEach(function(data) {
var subject = {
name: data.val().name,
imgUrl: data.val().imgUrl,
description: data.val().description,
teachers: data.val().teachers
}
tempArr.push(subject);
});
observer.next(tempArr);
});
// this.broadcastUpdate();
});
}
And my component:
export class SubjectsCmp implements AfterViewInit, OnInit, OnChanges {
constructor(
private _subjectsService: SubjectsService
) {
}
ngOnInit() {
this._subjectsService.getSubjects().subscribe( subjects => this.subjects = subjects);
}
}
I've looked a bit at the documentation for RxJS but to no avail. I thought I could rewrite it to follow the example they give::
var subscription = source.subscribe(
function (x) {
console.log('Next: %s', x);
},
function (err) {
console.log('Error: %s', err);
},
function () {
console.log('Completed');
});
But 'Completed' never fires.
Angular 2's onChanges observer only responds to changes caused by input events, so that won't work either. Basically I just need to run a method after the array is populated, I'm thinking I'm missing something obvious?