add(){
var newEvent = null;
try
{
newEvent = document.createEvent("KeyEvents");
newEvent.initKeyEvent("keypress", true, true, window,false, false, false, false, 0, 32);
}
catch(ex)
{
console.log(ex);
newEvent = document.createEvent("KeyboardEvent");
newEvent.initKeyboardEvent('keypress', true, true, window, false, false, false, false, 32, 0);
}
// e.preventDefault();
document.getElementById('surname').dispatchEvent(newEvent);
}
<input type="text" id="surname" name="surname" placeholder="आडनाव" [(ngModel)]="surName">
<button class="btn btn-primary" (click)="add();" id="add" >Fire</button>
add(){
var newEvent = null;
try
{
newEvent = document.createEvent("KeyEvents");
newEvent.initKeyEvent("keypress", true, true,window,false, false, false, false, 0, 32);
}
catch(ex)
{
console.log("aa ",ex);
newEvent = document.createEvent("KeyboardEvent");
newEvent.initKeyboardEvent('keypress', true, true, window, false, false, false, false, 32, 0);
}
}
<button class="btn btn-primary" (click)="add();" id="add" >Fire</button>