Help needed! I've created a simple example that should be working, but unfortunately it's not :( My onClick()
function doesn't seem to trigger the console.log as expected. Can someone help me figure out what I'm doing wrong?
@Component({
templateUrl: 'sandbox.template.html'
})
export class SandBoxPage implements OnInit {
dataSubject: Subject<string> = Subject.create();
data$: Observable<string>;
constructor(private platform: Platform) {
this.data$ = this.dataSubject
.asObservable()
.startWith("First value in the observable");
}
onClick() {
console.log("onClick()");
this.dataSubject.next(Date.now + " value");
}
ngOnInit() {
console.log("ngOnInit()");
this.data$.subscribe((v) => {
console.log("new value", v);
}, (err) => {
console.log("Error", err);
});
}
}
I've attached a button to the onClick()
, but for some reason, the console.log inside my subscribe method is not getting called. It only displays once with the initial value set by startsWith
.