I tried this exact directive yesterday and it didn't work, but I just realized why. It was due to my inexperience with creating custom directives. The cli added it to my declarations in my app.module file and I assumed it would be available to other modules that I have created. But it doesn't work that way. I just created a separate module for my custom directives and added that directive to declarations and exports. Now when I import that module the directive is available.😀 And it works! I'm now bald for nothing! Thank you, gentlemen. Dave
On Fri, Mar 1, 2019 at 1:34 PM <sc...@ser.vi> wrote: > Create a directive. For Angular 2+ > > import { AfterContentInit, Directive, ElementRef, Input } from >> '@angular/core'; >> @Directive({ >> selector: '[appAutoFocus]' >> }) >> export class AutoFocusDirective implements AfterContentInit { >> @Input() public appAutoFocus: boolean; >> public constructor(private el: ElementRef) { >> } >> public ngAfterContentInit() { >> setTimeout(() => { >> this.el.nativeElement.focus(); >> }, 500); >> } >> } > > > Then in your component form, include the tag > > <input type="text" appAutoFocus class="form-control"> > > -- > You received this message because you are subscribed to the Google Groups > "Angular and AngularJS discussion" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to angular+unsubscr...@googlegroups.com. > To post to this group, send email to angular@googlegroups.com. > Visit this group at https://groups.google.com/group/angular. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group. To unsubscribe from this group and stop receiving emails from it, send an email to angular+unsubscr...@googlegroups.com. To post to this group, send email to angular@googlegroups.com. Visit this group at https://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.