I am working on a angular application and have a scenario where i want to focus on a text field on page load. i have tried HTML5 autofocus but have to find an alternative solution for this since there is a browser compatibility issue for the same.
I am planning to invoke a function on page load which will focus on the input field i wanted. I have the following functions with Angular ng-init and onload to load the function.
I am not sure which method should i follow in the angular context as i am little confused between their difference.
onload
<body onload="focusOnInput()">
<form name="resetPasswordForm">
<input name="NewPassword" type="password"/>
</form>
</body>
<script>
function focusOnInput() {
document.forms["resetPasswordForm"]["NewPassword"].focus();
}
</script>
Angular ng-init
<body in-init="focusOnInput()">
<form name="resetPasswordForm">
<input name="NewPassword" type="password"/>
</form>
<script>
function focusOnInput() {
document.forms["resetPasswordForm"]["NewPassword"].focus();
}
</script>
</body>