Peter Boomsma
Peter Boomsma

Reputation: 9844

Rx subject is undefined

In this Namespace I export a Rx subject of type string:

namespace something.TaskHandling {

  export const taskSelected$ = new Rx.Subject<String>();

In my TaskListComponent class that is in the something.TaskHandling.Overview namespace I have:

public clickListItem() {
  taskSelected$.onNext('responsive-view-filters');
}

And in my ResponsiveNavigationComponent in the something.CustomerService namespace I import the subject:

import taskSelected$ = something.TaskHandling.taskSelected$;

I initiate the stream in my OnInit:

public $onInit() {
    this.observeTaskUpdates();
}

private observeTaskUpdates(): void {
    taskSelected$
        .filter(classValue => !!classValue)
        .subscribe(classValue => {
            this.toggleView(classValue);
        });
}

This code compiles with no issue and when I go to definition on the taskSelected I end up at the exported taskSelected$ subject.

But when I run the app I get this in my ResponsiveNavigationComponent.ts:

TypeError: Cannot read property 'filter' of undefined

So the taskSelected$ is not defined in my ResponsiveNavigationComponent class. What am I missing?

Upvotes: 0

Views: 128

Answers (1)

Peter Boomsma
Peter Boomsma

Reputation: 9844

It wasn't a order issue, I had to hard reference the actual file where the taskSelected$ const was initiated > /// <reference path="../TaskHandling/module.ts"/>. Not sure if this is a solution to a underlying issue.

Upvotes: 0

Related Questions