Create a new Angular project with the experimental patch (v0.8.1). The app runs fine the first time but if you update a file (say home.component.html) the browser goes blank and you see a bunch of errors in the console:
EXCEPTION: Error in :0:0 caused by: The selector "app" did not match any elements
Did you rename the root component from <app>?
Check your Views/Home/index.cshtml, and also what your app.component.ts selector is.
Wasn't able to reproduce this one locally.
Nope.
This generator can also be run with: yo aspnetcore-spa
_-----_ โญโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
| | โ Welcome to the ASP.NET โ
|--(o)--| โ Core Single-Page App โ
`---------ยด โ generator! โ
( _ยดU`_ ) โ โ
/___A___\ /โ Version: 0.8.1 โ
| ~ | โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
__'.___.'__
ยด ` |ยฐ ยด Y `
? Framework Angular 2.4.5 (experimental)
? What type of project do you want to create? project.json (compatible with .NET Core tooling preview 2 and Visual Studio 20
15)
? Do you want to include unit tests? Yes
Ran: cross-env ASPNETCORE_ENVIRONMENT=Development dotnet run
Then changed home.component.html header to: <h1>Hello, world! XXX</h1>
Save => blank screen with error.
When HMR updates modules, it detaches and reattaches changed components. DomRenderer.prototype.detachView removes all component elements which have parentNode defined (for app element it will be body element). As a temporary bypass I use
ngOnDestroy(): void {
document.body.appendChild(document.createElement("app"));
}
I also am seeing this. Thank you @nikitadmitry - I added that line in the ctor of app.component and this has helped resolve the issue for me also.
I also have not changed the default name app as the selector.
@nikitadmitry Thank you for the interim fix - I'm back in business over here as well
For me HMR broke with angular 2.4.6.
We reverted back to 2.4.5 and it works.
Thanks for the report. I've published generator-aspnetcore-spa 0.8.2 which pins to Angular 2.4.5. I'll look at relaxing this versioning restriction when I get a chance to investigate the issue with 2.4.6.
The template is now updated to support HMR with newer Angular 2.x (tested with 2.4.7).
Most helpful comment
When HMR updates modules, it detaches and reattaches changed components. DomRenderer.prototype.detachView removes all component elements which have parentNode defined (for app element it will be body element). As a temporary bypass I use
ngOnDestroy(): void { document.body.appendChild(document.createElement("app")); }