I have a very simple test component which looks like this:
@Component({
selector: "test-component",
template: "<div>Test</div>",
})
export class TestComponent implements OnInit {
private test : number = 0;
private service : ClientsService;
constructor(s : ClientsService) {
this.service = s;
}
public ngOnInit() {
this.service.loadAllClients().subscribe(d => {
this.test = 1;
});
let comp = this;
}
}
The client service returns an Observable but my question is about the 'test' variable. After the component loads, the first and the first breakpoint is hit, the value of 'test' is 0
However, when the breakpoint inside the 'subscribe()' is hit, the 'test' becomes undefined. Any assignments done inside the lambda do not take effect.

What am I missing here to do proper assignment inside the 'subscribe()'?
thisto refer to the component inside the callback. Print the value in the console, and see if it's printed properly. - JB Nizet