Adding FrontEnd element properties and JS listeners
In some scenarios, the migrated application has client-side Javascript logic and you will need to update the implementation manually, this way you can use the migrated application components or use the "Angular way" to accomplish the legacy behavior and take full advantage of the new technology.
Renderer
You can use Angular's renderer to add attributes, classes, styles or properties easily to an element.
For example, if you want to add a style or update a value you can use the renderer's setStyle and setProperty methods.
myFunction(): void {consttb=document.querySelector<HTMLInputElement>("#textbox1 input"//textbox1 is a component, we need to access the root html element );constinpName=document.querySelector<HTMLInputElement>("#input1");this.render.setProperty(tb,"value",inpName.value);this.render.setStyle(tb,"fontWeight","bold");this.render.setStyle(tb,"color","green");}
If you have custom listeners and they cannot be converted using the WebMAP infrastructure, you can select the specific element and use the addEventListener.
For example:
Legacy click listener (jQuery):
$("#btn1").click(function (e) {// custom logic to be executed every time the button's click is triggered });
Legacy html:
<asp:LinkButtonID="btn1"runat="server"/>
Manually converted TypeScript:
addBtnListener(): void {document.querySelector("#btn1 a").addEventListener("click", (event) => {// custom logic to be executed every time the button's click is triggered });}
We added the click listener to the anchor element, but you can add any available event for a specific element.