2017-03-07 6 views
0

htmlスパンタグで自動フォーカスを有効にするにはどうすればよいですか?私は.focus()を使って自動フォーカス属性の代わりに動作させようとしましたが、これはどちらも動作しません。htmlスパンタグでオートフォーカスが機能しますか?

<span class="newCheckbox" tabindex="0" #compareSpan (load)="compareSpan.focus()"> 

答えて

1

このような何か試してみてください:

//component 
import { ViewChild } from '@angular/core'; //import ViewChild if not already done 

@ViewChild('compareSpan') cs; //select your span 

ngAfterViewInit() {    
     this.cs.nativeElement.focus(); //focus it at after view initialization 
    } 
関連する問題