In my app, I have a comment list, while I click one of these comments, it means that I want to reply this comment. So I want to focus input label while I click the comments. But it doesn’t work.
In HTML:
<button ng-click="Focus()">Focus</button>
<input type="text" id="test_input" placeholder="white your comment"></input>
In js:
$scope.Focus() {
var oInput = document.getElementById("test_input");
oInput.focus();
}
Really, is that the only way.
Does it take a directive to do something that has existed in Javascript/HTML for over 20 years?
There must be a better way than having to write a custom directive to perform a native method surely please tell me there is.
By using a directive you are making sure that the code is modular and scalable. If you name your directive something like onClickFocusId and implement it as a custom click handler, you have just created a directive which can be used on pretty much any html element out there.