Guest User

Untitled

a guest
Feb 19th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. export class Question {
  2. constructor(
  3. public Id: number,
  4. public Title: string,
  5. public Text: string,
  6. public OriginalUrl: string,
  7. public Answers: Answer[]
  8. ){}
  9.  
  10. isAnsweredCorrectly():boolean {
  11.  
  12. for(let answer of this.Answers){
  13. if(
  14. (!answer.IsCorrect && answer.IsSelected) ||
  15. (answer.IsCorrect && !answer.IsSelected)) {
  16.  
  17. return false;
  18. }
  19. }
  20.  
  21. return true;
  22. }
  23. }
  24.  
  25. <ul class="list-group h-100">
  26.  
  27. <a class="list-group-item list-group-item-action"
  28. *ngFor="let q of questions; let i = index;"
  29. [ngClass]="getClasses(q)"
  30. (click)="selectQuestion(q)">
  31. Question {{i+1}}
  32. </a>
  33.  
  34. </ul>
  35.  
  36. export class QuestionListComponent implements OnInit {
  37.  
  38. @Input() questions:Question[];
  39. @Input() currentQuestion:Question;
  40.  
  41. ...
  42.  
  43. getClasses(question:Question):any{
  44. return {
  45. 'list-group-item-primary': question == this.currentQuestion,
  46. 'list-group-item-success': question.isAnsweredCorrectly(),
  47. 'list-group-item-danger': !question.isAnsweredCorrectly()
  48. };
  49. }
  50. }
  51.  
  52. QuestionListComponent.html:3 ERROR TypeError: question.isAnsweredCorrectly is not a function
  53. at QuestionListComponent.getClasses (question-list.component.ts:33)
  54. at Object.eval [as updateDirectives] (QuestionListComponent.html:5)
Add Comment
Please, Sign In to add comment