angular2-universal-starter icon indicating copy to clipboard operation
angular2-universal-starter copied to clipboard

Universal setTitle

Open vaseker opened this issue 9 years ago • 9 comments

Does it and it means that there is no Universal Title service yet?

This code crashes while building server bundle.

import { Title } from 'angular2/platform/browser';

./node_modules/angular2/src/facade/browser.js:4 var win = window; ^ ReferenceError: window is not defined

vaseker avatar Feb 08 '16 09:02 vaseker

Just ran into it as well...not sure if it's a bug or just not recommended to use with Universal/Web Workers.. however, the app still seems to not load even if I turn off WW and SS in the constants and have Title in the providers.

qdouble avatar Feb 08 '16 13:02 qdouble

@vaseker There are no Title services for web workers nor for server side at the moment. I can implement them temporary in this starter (I'll do it after #51 is merged).

@qdouble Hmm.. I think it's bug. The application should work if you turn off server side and web workers. But at the same time you should not use import { something } from 'angular2/platform/browser' for your components, you should use it only in boot_browser file. All code in your angular2 components should be absolutely environment agnostic.

As I've said I'll solve the issue after #51.

alexpods avatar Feb 08 '16 16:02 alexpods

@alexpods thanks for explanation. +1 for Universal Title service after #51 merged)

vaseker avatar Feb 08 '16 17:02 vaseker

https://github.com/angular/angular/blob/master/modules/angular2/src/platform/browser/title.ts

PatrickJS avatar Feb 09 '16 05:02 PatrickJS

@gdi2290 Thanks that helped.

Edit: It works like normal, I just made a mistake. Thanks again.

qdouble avatar Feb 09 '16 05:02 qdouble

It doesn't work to set title in web workers though unfortunately.

qdouble avatar Feb 09 '16 07:02 qdouble

Related: https://github.com/angular/angular/issues/7301

alexpods avatar Feb 29 '16 07:02 alexpods

Could it be implemented now with your commit to universal by any developer? Could you give some examples of how it can be implemented manually, while core team doesn't have that service?

Settler avatar Feb 29 '16 19:02 Settler

@Settler See simple implementation here. It should work for every environment that mocks real document (DOCUMENT service). You have to use renderDocumentWithPreboot instead of renderToStringWithPreboot here to make it work.

alexpods avatar Feb 29 '16 21:02 alexpods