<form novalidate [formGroup]="form" (ngSubmit)="formValidated()">
<div class="form-group">
- <textarea placeholder="Add comment..." formControlName="text" [ngClass]="{ 'input-error': formErrors['text'] }">
+ <textarea placeholder="Add comment..." formControlName="text" [ngClass]="{ 'input-error': formErrors['text'] }" #textarea>
</textarea>
<div *ngIf="formErrors.text" class="form-error">
{{ formErrors.text }}
-import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
+import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
import { FormBuilder, FormGroup } from '@angular/forms'
import { NotificationsService } from 'angular2-notifications'
import { Observable } from 'rxjs/Observable'
export class VideoCommentAddComponent extends FormReactive implements OnInit {
@Input() video: Video
@Input() parentComment: VideoComment
+ @Input() focusOnInit = false
@Output() commentCreated = new EventEmitter<VideoCommentCreate>()
'text': VIDEO_COMMENT_TEXT.MESSAGES
}
+ @ViewChild('textarea') private textareaElement: ElementRef
+
constructor (
private formBuilder: FormBuilder,
private notificationsService: NotificationsService,
ngOnInit () {
this.buildForm()
+
+ if (this.focusOnInit === true) {
+ this.textareaElement.nativeElement.focus()
+ }
}
formValidated () {