Here, I will explain how to set focus on text box using ElementRef. Demo.html : <input type="text" class="form-control" value="" #barcode placeholder="Barcode" [(ngModel)]="Barcode" (blur)="SetFocus()" /> Demo.Component.ts : import { Component, OnInit, ElementRef } from '@angular/core'; export class StockDataTableComponent implements OnInit, OnChanges { @ViewChild('Barcode') barcode: ElementRef; constructor(){} function SetFocus(){ this.barcode = ""; this.barcode.nativeElement.focus(); } }
Here you can find solution of your code problem & errors.