I am currently working on a project in Angular 2 where I am incorporating observables and services in typescript. However, I have encountered an issue where the event handler in my observable is not being triggered.
Below is the code snippet:
The Service:
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs/Subject';
@Injectable()
export class AllDataPageService {
receptorFilterChanged$ = new Subject<any>();
}
This service includes an event called receptorFilterChanged.
Here is the component responsible for firing the event (located at ~\src\results\app\all-data-page)
import { AllDataPageService } from './all-data-page.service';
...
@Component({
selector: 'all-data-page',
templateUrl: './all-data-page.component.html',
styles: [require('./all-data-page.style.scss')],
providers: [AllDataPageService]
})
export class AllDataPageComponent implements OnInit {
...
constructor(private allDataPageService: AllDataPageService) {}
...
filterByReceptorTag() {
...
this.allDataPageService.receptorFilterChanged$.next(50.0);
...
}
...
}
The line this.allDataPageService.receptorFilterChanged$.next(50.0) within the function filterByReceptorTag() above is responsible for triggering the event. It has been verified in the Chrome debugger that this line of code is executed successfully.
Now, here's the component handling the receptorFilterChanged event (located at ~\src\results\app\shared\components\all-data-row)
import { AllDataPageService } from '../../../all-data-page/all-data-page.service';
...
@Component({
selector: 'all-data-row',
templateUrl: './all-data-row.component.html',
styles: [ require('./all-data-row.style.scss') ],
encapsulation: ViewEncapsulation.None,
providers: [AllDataPageService]
})
export class AllDataRowComponent implements OnInit {
...
constructor(private allDataPageService: AllDataPageService) {
this.allDataPageService.receptorFilterChanged$.subscribe(
(value) => {
...
}
);
}
...
}
Despite firing the receptorFilterChanged event, the subscribed event handler mentioned above fails to execute.
If anyone could provide insights into what might be causing this issue, it would be greatly appreciated.
Thank you.