I'm using Angular 1.4.5 with Angular Ui Router, and for text formatting reasons I'm trying to get addEventListener to perform a function when a text field is blured. The problem I'm running into, however, is that on the load state, the element I'm trying to find does not yet exist because it doesn't exist on the template that loaded, so it never attached to the element
Other than editing each and every template so that it loads initEventListeners(), or manually adding onblur to each element as needed, is there a (preferably Vanilla) way to add event listeners when changing routes or way to trigger the function when navigating between states?
Here's the relevant pieces of JS, the rest is properly strung together with UI-Router and Angular
function initEventListeners() {
'use strict'
if (document.contains(document.getElementById('phone'))) {
document.getElementById('phone').addEventListener('blur', formatPhoneNumber);
}
}
window.onload = function () {
'use strict';
runTicker();
setTimeout(cycleFooterText, 4000);
initEventListeners();
}