The observable function is NOT http; the function must be local, but it needs to be subscribed. This is the best I could do based on online example:
export class AppComponent implements OnInit {
title = 'Sample';
message1 = '';
observable = new Observable((subscriber) => {
subscriber.next(1);
subscriber.next(2);
subscriber.next(3);
setTimeout(() => {
subscriber.next(4);
subscriber.complete();
}, 1000);
});
constructor() {}
ngOnInit() {
}
public getUser() {
this.observable.subscribe({
next(x) {
this.message1 = 'got value ' + x; <--------------------------
},
error(err) {
console.error('something wrong occurred: ' + err);
},
complete() {
console.log('done');
},
});
console.log('just after subscribe');
}
}
The subscriber has no access to anything outside of itself (the message1 I show with arrows). Thoughts?