Why am I receiving an error message saying "test is not defined" in this code? Even though I have properly defined the variable in another service file, it seems to be causing issues here. Any insights on what could be going wrong?
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
@Injectable()
export class OnlineTestService {
// please update setters and getters based on your requirements
constructor(private http: HttpClient) {
var test = "";
this.getJSON().subscribe(data => {
return data;
});
this.getANSWERS().subscribe(data => {
return data;
});
};
questionAnswers(input){
test = input;
};
retrieveAnswers(){
return test;
};
public getJSON(): Observable<any> {
return this.http.get("assets/questions.json");
};
public getANSWERS(): Observable<any> {
return this.http.get("assets/answers.json");
};
}
UPDATE:
export class RegistrationService {
// please update setters and getters based on your requirements
constructor(){
var name = "";
}
addUser(input){
name = input.name;
}
retrieveUser(){
return name;
}
}