[AngularJS] Re: How to set focus list composed from div with *ngFor

2019-09-17 Thread Dev C
Also I want to focus the div tag which has been selected by user in searchbox On Tuesday, September 17, 2019, Dev C wrote: > Thanks Sander > > @ViewChildren('dataw') rows: QueryList |undefined > > and in method > > SetListFocus(){ > > this.rows.first.nativeElement.focus(); > > > } > > I did

[AngularJS] Re: How to set focus list composed from div with *ngFor

2019-09-17 Thread Dev C
Thanks Sander @ViewChildren('dataw') rows: QueryList |undefined and in method SetListFocus(){ this.rows.first.nativeElement.focus(); } I did this but not working. On Tuesday, September 17, 2019, Sander Elias wrote: > Well, viewChild returns the occurrence of the template var. ngFor

[AngularJS] Re: How to set focus list composed from div with *ngFor

2019-09-17 Thread Sander Elias
Well, viewChild returns the occurrence of the template var. ngFor probably has multiple. also, its getting set afterViewInit. Try using @viewChildren it has a queryList that you can iterate over for multiple instances -- You received this message because you are subscribed to the Google Groups

[AngularJS] Re: How to set focus list composed from div with *ngFor

2019-09-17 Thread Dev C
Yes but I have template with div with ngFor. I did same in my example and it is not working. On Tuesday, September 17, 2019, Sander Elias wrote: > Hi Dev, > > > Setting the focus from withing angular is the same as for native js. > > @ViewChild("someTemplateVar") someTemplateVar: ElementRef; >

[AngularJS] Re: How to set focus list composed from div with *ngFor

2019-09-17 Thread Sander Elias
Hi Dev, Setting the focus from withing angular is the same as for native js. @ViewChild("someTemplateVar") someTemplateVar: ElementRef; someMethod(): void { if (this.someTemplateVar.nativeElement) { this.someTemplateVar.nativeElement.focus(); } } Wrapping inside the if makes sure

[AngularJS] Re: How to set focus list composed from div with *ngFor

2019-09-17 Thread Dev C
I understand that but how about focusing on given element, if you can help.me.with this. May be giving some example. Thanks On Tuesday, September 17, 2019, Sander Elias wrote: > Hi, > > Why are all the `?` in the code? you are inside a ngFor loop, so it's > defined by definition. > Then the

[AngularJS] Re: How to set focus list composed from div with *ngFor

2019-09-17 Thread Sander Elias
Hi, Why are all the `?` in the code? you are inside a ngFor loop, so it's defined by definition. Then the function seems completely unrelated to the template shown. There is too little to help you. As a tip, if you are inside a ngFor loop, it is a bad idea to set variables on a component