I'm currently working with Observable
and ChangeDetectionStrategy
to notify other components about any changes that occur. However, I am encountering an issue where the Observable object addItemStream
is coming up as undefined. Can anyone spot what might be causing this problem?
import { Component, ChangeDetectionStrategy, ChangeDetectorRef, Input } from '@angular/core'
import { ROUTER_DIRECTIVES, Router } from '@angular/router';
import {Observable} from 'rxjs/Observable';
@Component({
selector: 'bp-header',
templateUrl: 'app/header.component.html',
directives: [ROUTER_DIRECTIVES],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class HeaderComponent {
@Input() addItemStream: Observable<any>;
public isActive: number;
public language: string = "en";
constructor(private cd: ChangeDetectorRef) {}
ngOnInit() {
this.isActive = 1;
}
ngAfterViewInit() {
this.addItemStream.subscribe(() => {
this.setLanguage; // application state changed
this.cd.markForCheck();
})
}
public setLanguage = (language: string) => {
if (this.language === language) { return }
else { this.language = language };
}
public setActive(active: number) {
if (this.isActive === active) return;
this.isActive = active;
}
}