beeman / tutorial-angular-cli-hmr

Tutorial: Enable HRM in Angular CLI apps
https://medium.com/@beeman/1b0d13b80130
19 stars 3 forks source link

Doesn't keep state #2

Closed richarddavenport closed 7 years ago

richarddavenport commented 7 years ago

This appeared to be promising, but after trying a simple test, this isn't actually doing true hot module reloading. What I mean is the dom state is gone after the modules are reloaded. I added an input to the app.component.html:

<h1>
  {{title}}
</h1>
<input type="text" name="text" value="">

Here's a screencast: hmr

Is this the expected behavior?

CWSpear commented 7 years ago

I have the same question. It looks like it just recompiles the root component... but I, too, was hoping for saving state. One of the best benefits of hmr is you can style a modal or something and see the changes without having to re-open the modal.

richarddavenport commented 7 years ago

I actually figured this out. With HMR it only knows about state that is stored in a service/component/module, not just anything in the DOM. So, in my example, if the input in the template was using ngModel, then it would keep that state. HMR, from my limited experience, is not able to just grab whatever was in the DOM. That's not how it works. Hope this helps! I think we can close this now.