troubleshooting Question

JavaScript not working in Angular

Avatar of Stefan Motz
Stefan MotzFlag for United States of America asked on
6 Comments1 Solution129 ViewsLast Modified:
Hi Experts,
I'm trying to make a simple JavaScript page work with Angular, but I don't get the same results as in my browser when I open it from Notepad.
This is the code of the page, working fine when I display it in the browser:
  function display()
  document.getElementById("errorLabel1").innerHTML = document.getElementById("searchBox").value; 
  document.getElementById("searchBox").value = "";

  <input type="text" id="searchBox">
  <input type="button" value="Submit" id="mySearch" onClick="display()"/>

You typed: <div id="errorLabel1"></div>

Open in new window

In Angular I paste this code in the app.component.html:
app.component.htmlIt won't return any results after I do ng serve
Do I need additional imports in the app.component.ts file in order to make it work? Right now it only has one import:
app.component.tsPlease let me know what I am missing. Thank you very much in advance!
Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros