There is a lot of contents on this in stack overflow but none seems to work for my case. I have an input text field and I want to simulate keypress event to fill the text fi
IMHO you're going about this all wrong. Angular is not "listening" to keypress or the like. It is listening to change and input events. See the example below. It does (admittedly it is simple) what you need.
var iButton = document.getElementById('inputButton');
iButton.addEventListener('click', simulateInput);
var cButton = document.getElementById('changeButton');
cButton.addEventListener('click', simulateChange);
function simulateInput() {
var inp = document.getElementById('name');
var ev = new Event('input');
inp.value =inp.value + 'a';
inp.dispatchEvent(ev);
}
function simulateChange() {
var inp = document.getElementById('name');
var ev = new Event('change');
inp.value = 'changed';
inp.dispatchEvent(ev);
}
Input something in the input box:
Name :
Hello {{name}}