Skip to content

Instantly share code, notes, and snippets.

@griffgruff
Created May 1, 2020 17:24
Show Gist options
  • Select an option

  • Save griffgruff/02e29aa4186cc8240b6876d643c80a2b to your computer and use it in GitHub Desktop.

Select an option

Save griffgruff/02e29aa4186cc8240b6876d643c80a2b to your computer and use it in GitHub Desktop.
focus
import { Component, AfterViewInit, ElementRef, ViewChild } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent implements AfterViewInit {
name = 'Angular 8 by Example: ElementRef';
@ViewChild("beer") divView: ElementRef;
//@ViewChild('alert', { read: ElementRef }) alert:ElementRef;
ngAfterViewInit(){
//console.log(this.divView);
this.divView.nativeElement.focus()
}
}
<hello name="{{ name }}" #test ></hello>
<div #beer >here</div>
<form action="/action_page.php">
<label for="fname" #just>First name:</label>
<input type="text" id="fname" name="fname" #here><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="submit" value="Submit">
</form>
<div #myDiv>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment