I am very new to angular and am learning through the Heroes tutorial. I am on the part concerning two-way binding. I have learned all the different binding types and tried to implement them. Interpolation and property binding work fine. However, when I tried two-way binding (and event binding) in the file that was specified in the tutorial with the correct imports as well. So that someone is able to see it. The HTML file is heroes.component.html and it is the template for heroes.component.ts with the component name app-heroes, which is called in app.component.html The elements are on the bottom of the webpage.
I have tried using the event binding within the app.component (ts and HTML), and it seems to work (blue button), but not the two-way binding which is below the blue button (hero age). neither of these two work with the heroes component (Hero Name and Hello Button).
The working link is in the comments, wouldn’t work when pasting it on the post for some reason
Apologies if any confusing wording and Thank You!
2
Answers
Remember: an HTML document should have only one
<body>
elementRemove
<body></body>
fromheroes.component.html
I found this by viewing the console logs within stackblitz. From there you see there is a hydration issue and checking the html is a proposed solution.
We only want
<body></body>
in one place, inindex.html
Error for reference:
You can refer the below link for reference : https://medium.com/@matsal.dev/angular-how-two-way-binding-works-with-ngmodel-19c5e6ebe268