import { Component, Input, OnInit, ViewChild, ElementRef, AfterViewInit } from '@angular/core'; @Component({ selector: 'bom-copy', templateUrl: 'copy-bom-modal.component.html', styleUrls: ['copy-bom-modal.component.scss'] }) export class CopyBomModalComponent implements OnInit, AfterViewInit { @Input() data: any; @Input() content: string; @ViewChild('name') nameInput: ElementRef; constructor() {} ngOnInit() { this.data.newBomName = `${this.data.name} Copy`; } ngAfterViewInit() { // If we don't do this (the setTimeout=0) the screen will // scroll to the bottom of the page setTimeout(() => { this.nameInput.nativeElement.focus(); }, 0); } }