diff --git a/src/app/content-answer.service.ts b/src/app/content-answer.service.ts index e414d1d2ac4bcfa1eec16cea94ad9624f84f5eb6..35c6e2419f88bec8fe68bc1a6c03972d071913a3 100644 --- a/src/app/content-answer.service.ts +++ b/src/app/content-answer.service.ts @@ -16,8 +16,9 @@ export class ContentAnswerService extends ErrorHandlingService { super(); } - getAnswerTexts(): Observable<AnswerText[]> { - return this.http.get<AnswerText[]>(this.answerUrl).pipe( + getAnswerTexts(contentId: string): Observable<AnswerText[]> { + const url = `${this.answerUrl}/?contentId=${contentId}`; + return this.http.get<AnswerText[]>(url).pipe( catchError(this.handleError('getAnswerTexts', [])) ); } diff --git a/src/app/content-answers-list/content-answers-list.component.html b/src/app/content-answers-list/content-answers-list.component.html index 78bbc610924abfc918fce806dfb006e80d3d6129..d1205e828c48078f9500b29a95674ca9d06dd6e0 100644 --- a/src/app/content-answers-list/content-answers-list.component.html +++ b/src/app/content-answers-list/content-answers-list.component.html @@ -1,9 +1,8 @@ <mat-list> <h3 mat-subheader>Answers</h3> - <mat-list-item *ngFor="let textAnswer of filteredTextAnswers"> + <mat-list-item *ngFor="let textAnswer of textAnswers"> <button mat-button routerLink="{{textAnswer.id}}"> - <!-- *ngIf="textAnswer.subject === content($id)"> --> {{textAnswer.body}} </button> </mat-list-item> -</mat-list> +</mat-list> \ No newline at end of file diff --git a/src/app/content-answers-list/content-answers-list.component.ts b/src/app/content-answers-list/content-answers-list.component.ts index 73f7d15b1dd51ad54b76565130572db01a7645b7..ef2df1a523d50da21a770714a985b066b40072dc 100644 --- a/src/app/content-answers-list/content-answers-list.component.ts +++ b/src/app/content-answers-list/content-answers-list.component.ts @@ -1,10 +1,8 @@ import { Component, OnInit } from '@angular/core'; import { ContentAnswerService } from '../content-answer.service'; import { AnswerText } from '../answer-text'; -import { ContentDetailComponent } from '../content-detail/content-detail.component'; -import { Content } from '../content'; import { ActivatedRoute } from '@angular/router'; -import { forEach } from '@angular/router/src/utils/collection'; +import { ContentService } from '../content.service'; @Component({ selector: 'app-content-answers-list', @@ -13,29 +11,29 @@ import { forEach } from '@angular/router/src/utils/collection'; }) export class ContentAnswersListComponent implements OnInit { textAnswers: AnswerText[]; - content: Content[]; - filteredTextAnswers: AnswerText[]; - constructor(private contentAnswerService: ContentAnswerService, - private contentDetailComponent: ContentDetailComponent, - private route: ActivatedRoute) {} + constructor( + private contentService: ContentService, + private contentAnswerService: ContentAnswerService, + private route: ActivatedRoute + ) { } ngOnInit() { - this.getAnswerTexts(); this.route.params.subscribe(params => { - this.contentDetailComponent.getContent(params['id']); // todo: filtered answers befüllen + this.getContent(params['id']); }); - for (let i = 0; i < this.textAnswers.length; i++) { - console.log('kre'); - for (let j = 0; i < this.content.length; j++) { - if (this.textAnswers[i].contentId === this.content[j].id) { this.filteredTextAnswers.push(this.textAnswers[i]); } - } - } } - getAnswerTexts(): void { - this.contentAnswerService.getAnswerTexts().subscribe(textAnswers => { - this.textAnswers = textAnswers; - }); + getContent(id: string): void { + this.contentService.getContent(id).subscribe(params => { + this.getAnswerTexts(params['id']); + }) + } + + getAnswerTexts(id: string): void { + this.contentAnswerService.getAnswerTexts(id) + .subscribe(textAnswers => { + this.textAnswers = textAnswers; + }); } } diff --git a/src/app/in-memory-data.service.ts b/src/app/in-memory-data.service.ts index 49a107eacb6d9164fb6db63960061a076ba4a6d1..85bb2914a07c328290ca00f4e5cd6644a1171e6b 100644 --- a/src/app/in-memory-data.service.ts +++ b/src/app/in-memory-data.service.ts @@ -107,7 +107,7 @@ export class InMemoryDataService implements InMemoryDbService { { id: '1', revision: '1', - contendId: '1', + contentId: '1', round: '1', subject: 'Textaufgabe 1', body: 'gamma, delta', @@ -117,7 +117,7 @@ export class InMemoryDataService implements InMemoryDbService { { id: '1', revision: '1', - contendId: '1', + contentId: '1', round: '1', subject: 'Textaufgabe 1', body: 'epsilon, phi', @@ -127,7 +127,7 @@ export class InMemoryDataService implements InMemoryDbService { { id: '2', revision: '2', - contendId: '2', + contentId: '2', round: '3', subject: 'Textaufgabe 2', body: 'Der Turm ist 20m hoch',