diff --git a/src/app/pages/answers/answers.component.ts b/src/app/pages/answers/answers.component.ts index a17b1a15..97071057 100644 --- a/src/app/pages/answers/answers.component.ts +++ b/src/app/pages/answers/answers.component.ts @@ -1,7 +1,9 @@ -import {ChangeDetectorRef, Component, OnInit} from '@angular/core'; +import {ChangeDetectorRef, Component, Inject, OnInit} from '@angular/core'; import {BaseComponent} from '../base-page/base.component'; import {ConfigService} from '../../config.service'; +import {DOCUMENT} from '@angular/common'; + @Component({ selector: 'framadate-answers', templateUrl: './answers.component.html', @@ -12,6 +14,7 @@ export class AnswersComponent extends BaseComponent implements OnInit { private answerList = []; constructor(config: ConfigService, + @Inject(DOCUMENT) private document: any, private cd: ChangeDetectorRef) { super(config); this.answerList = this.config.answers; @@ -32,8 +35,11 @@ export class AnswersComponent extends BaseComponent implements OnInit { text: '' }); this.cd.detectChanges(); // to refresh the view before focusing on the new input - const AnswersDomToFocus = document.querySelectorAll('.answers .answer'); - AnswersDomToFocus[AnswersDomToFocus.length - 1].focus(); + const AnswersDomToFocus = this.document.querySelectorAll('.answers .answer'); + const dom = AnswersDomToFocus[AnswersDomToFocus.length - 1]; + if (dom.focus) { + dom.focus(); + } } // add a new answer on the press of ENTER in an input