Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export class Question {
- constructor(
- public Id: number,
- public Title: string,
- public Text: string,
- public OriginalUrl: string,
- public Answers: Answer[]
- ){}
- isAnsweredCorrectly():boolean {
- for(let answer of this.Answers){
- if(
- (!answer.IsCorrect && answer.IsSelected) ||
- (answer.IsCorrect && !answer.IsSelected)) {
- return false;
- }
- }
- return true;
- }
- }
- <ul class="list-group h-100">
- <a class="list-group-item list-group-item-action"
- *ngFor="let q of questions; let i = index;"
- [ngClass]="getClasses(q)"
- (click)="selectQuestion(q)">
- Question {{i+1}}
- </a>
- </ul>
- export class QuestionListComponent implements OnInit {
- @Input() questions:Question[];
- @Input() currentQuestion:Question;
- ...
- getClasses(question:Question):any{
- return {
- 'list-group-item-primary': question == this.currentQuestion,
- 'list-group-item-success': question.isAnsweredCorrectly(),
- 'list-group-item-danger': !question.isAnsweredCorrectly()
- };
- }
- }
- QuestionListComponent.html:3 ERROR TypeError: question.isAnsweredCorrectly is not a function
- at QuestionListComponent.getClasses (question-list.component.ts:33)
- at Object.eval [as updateDirectives] (QuestionListComponent.html:5)
Add Comment
Please, Sign In to add comment