How can I effectively share question details and an array of options from one component to another using services? What is the recommended method for storing and retrieving these values from the service?
In my question-service class:
private static ques_optn : Array<QnA>;
constructor() { }
public setQuestion(qna :Array<QnA>) : void
{
qna.forEach(element => { QuestionService.ques_optn.push(element)});
}
public getQuestion() : Array<QnA>
{
return QuestionService.ques_optn;
}
In my login.ts class, I am setting the value to a variable:
{
ques_ans: Array<QnA> = [];
this.ques_ans; (contains the value)
this.questservice.setQuestion(this.ques_ans);
}
In my question.ts class, I am retrieving the value:</p>
this.ques = <QnA[]>this.questservice.getQuestion();
I aim to access the values stored in the "this.ques" variable in the question.ts class