I want to get 10 questions by Id using loop. But I get error:
(TS) Type 'Subscription' is missing the following properties from type 'Question': QuestionId, Content, TestId, Test
My Question class
import { Test } from './test';
export class Question {
QuestionId: number;
Content: string;
TestId: number;
Test: Test;
}
My get method in data.service
getQuestionById(id: number) {
return this.http.get(this.questionUrl + `/${id}`);
}
My Component
questions: Question[];
question: Question;
getQuestions() {
for (let i = 1; i < 11; i++) {
this.questions[i] =
this.dataService.getQuestionById(i)
.subscribe((data1: Question) => {
this.question = data1;
});
//this.questions.push(this.dataService.getQuestionById(1)
// .subscribe((data1: Question) => {
// this.question = data1;
// }););
}
}
How should I change my getQuestions() method to make it works?
this.questionsandthis.questiondeclared?