JavaScriptServices icon indicating copy to clipboard operation
JavaScriptServices copied to clipboard

Default Angular Template creates duplicate html and body tags

Open ghost opened this issue 9 years ago • 3 comments

Create a new ASP.NET Core 2.0 Web App with the default Angular template. Build and run. View the source. Note the html, head, and body tags located within the tag. The console also enumerates the errors. This is obviously unintended, and I assume is an artifact of the pre-renderer.

ghost avatar Aug 28 '17 11:08 ghost

I'm not sure why this is still a problem even though it was supposedly fixed: https://github.com/angular/universal/issues/347

I ended up putting the following in boot.server.ts for now:

                    resolve({
                        html: state.renderToString()
                            .replace('<html><head>', '')
                            .replace('</head><body>', '')
                            .replace(/<\s*app.*?>/,'')
                            .replace('</app></body></html>', '')
                    });

dmlsrc avatar Aug 28 '17 22:08 dmlsrc

@ltctech They only fixed it temporarily, then brought back the issue in a later version unfortunately.

@MarkPieszak has been working with the Angular team on hopefully improving the APIs around server-side rendering so we can get the distinct outputs (HTML, title, styles, etc.) separately instead of them all being mashed together in a big HTML document string. If Angular does implement that then we'll certainly make use of it, but failing that @ltctech's workaround is as good as it gets.

SteveSandersonMS avatar Sep 06 '17 13:09 SteveSandersonMS

@Anyone found a solution to this problem?

pravin271 avatar Dec 12 '17 10:12 pravin271