Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Prerender does not work with templateUrl or styleUrls #294

Closed

Description

@manekinekko

@jongood01 has reported this issue in the universal-starter

Components that have separate html and css files and reference them via templateUrl and styleUrls do not prerender but client-side still loads i.e. this doesn't work:

@Component({
  selector: 'app',
  templateUrl: 'path/to/my/template.html',
  styleUrls: ['path/to/my/stylesheet.css'],
})
But this does:

@Component({
  selector: 'app',
  template: `
<div>Here is my template</div>
`,
  styles: [`
   .classy {
        background: red;
   }
`],

see issue here: angular/universal-starter#43

Activity

  1. Bhushan001 commented on Mar 7, 2016

    @Bhushan001

    @manekinekko has this issue been resolved?

  2. PatrickJS commented on Mar 7, 2016

    @PatrickJS
    Contributor

    it shouldn't be resolved. the issues is that on the server the url needs to be a full url

  3. jesussobrino commented on Mar 16, 2016

    @jesussobrino

    I was getting crazy before I read this issue. I'm subscribing waiting for news.
    Thanks for a great work.

  4. creaux commented on Mar 16, 2016

    @creaux

    Hah, exactly. Webpack seems to be the solution in the meantime.

    On 16 Mar 2016, at 12:29, Jesús Sobrino notifications@github.com wrote:

    I was getting crazy before I read this issue. I'm subscribing waiting for news.
    Thanks for a great work.

    —
    You are receiving this because you are subscribed to this thread.
    Reply to this email directly or view it on GitHub

  5. Bhushan001 commented on Apr 5, 2016

    @Bhushan001

    @gdi2290 i tried using full url as templateUrl: 'http://localhost/app/app.component.html' but no success.

  6. helenitvn commented on Apr 5, 2016

    @helenitvn

    Try using this instead @Bhushan001:
    templateUrl: '/app/app.component.html'

  7. Bhushan001 commented on Apr 5, 2016

    @Bhushan001

    @helenitvn @gdi2290 I tried templateUrl: 'app/app.component.html'
    after that I was getting this error:
    EXCEPTION: Failed to load app/app.component.html ngOnInit Error: Failed to load app/app.component.html Async Error: Failed to load app/app.component.html ngOnStable Error: Failed to load app/app.component.html preboot Error: Failed to load app/app.component.html Rendering Document Error: Failed to load app/app.component.html ngOnRendered Error: Failed to load app/app.component.html

  8. helenitvn commented on Apr 5, 2016

    @helenitvn

    @Bhushan001: Could you show me your project structure?

    It works in my case.

    templateUrl

  9. Bhushan001 commented on Apr 5, 2016

    @Bhushan001

    @helenitvn in case of normal angular2 app it works.but I am trying to use it with universal-starter
    directory structrure

  10. helenitvn commented on Apr 5, 2016

    @helenitvn

    I also use universal-starter as my seed, too.

    In your case you need to use templateUrl: '/src/app/app.component.html' instead templateUrl: '/app/app.component.html'

  11. Bhushan001 commented on Apr 5, 2016

    @Bhushan001

    @helenitvn its still not working but this worked for me.
    templateUrl: 'http://localhost:3000/src/app/app.component.html'

  12. jeremythuff commented on Apr 6, 2016

    @jeremythuff

    For me templateUrl: '/src/app/view/dashboard.component.html' is not working. It throws "EXCEPTION: Error: Uncaught (in promise): Failed to load /src/app/view/dashboard.component.html"

    templateUrl: 'http://localhost:3000/src/app/view/dashboard.component.html' is grabbing the template but not waiting on asynchronous content before rendering.

  13. 11 remaining items

  14. Bhushan001 commented on May 2, 2016

    @Bhushan001

    @gdi2290 any success yet?

  15. Bhushan001 commented on May 10, 2016

    @Bhushan001

    @gdi2290 @jeffwhelpley we are working on a project in which this feature is required.I was wondering If u could provide any inputs on when this feature will be available?

  16. jeffwhelpley commented on May 10, 2016

    @jeffwhelpley
    Contributor

    Sorry for the delay in response @Bhushan001. Last week was crazy with ng-conf and we are just starting to get back into things. So, the status here is that we know what needs to change (modifications to the zones patch) and I have it right near the top of our overall priority list.

    @gdi2290 can you provide an update once you get the fix in for this?

  17. vinodbhargava commented on Jun 3, 2016

    @vinodbhargava

    Hi @gdi2290 , did you get a chance to look into this?

  18. jeffwhelpley commented on Jun 3, 2016

    @jeffwhelpley
    Contributor

    @vinodbhargava Patrick is working on this right now. This is one of out two top priorities right now as it is roadblocking several other things. You can expect to hear an update on this within the next week.

  19. durbonas commented on Jun 4, 2016

    @durbonas

    This worked for me:

    My component that contains my app ('my-app') in the index page looks like this:
    @Component({ moduleId: module.id, selector: 'my-app', templateUrl: 'app.component.html', styleUrls: ['app.css','font-awesome.min.css'], directives: [ROUTER_DIRECTIVES] })

    Every other component within that I navigate to looks like this:
    @Component({ selector: 'login', templateUrl: 'app/login.component.html', styleUrls: ['app/app.css', 'app/font-awesome.min.css'] })

    adding app/ seems to do the trick and my styles appear.

  20. durbonas commented on Jun 4, 2016

    @durbonas

    @gdi2290 @jeffwhelpley try "app/" not "/app/" - look at my comment above.

  21. PatrickJS commented on Jun 13, 2016

    @PatrickJS
    Contributor

    for templateUrl you need to __filename for moduleId here's an example
    https://github.com/angular/universal-starter/blob/master/src/app/home/home.component.ts#L4

    styleUrls doesn't work though so I need to look into that

  22. davidthor commented on Jun 29, 2016

    @davidthor

    I've been following this thread closely, and was just checking in to see if there's an update. Haven't gotten any of the proposed work-arounds to work as of yet, and would love to know more about the proposed patches coming down the pipeline.

    Thanks in advance.

  23. PatrickJS commented on Jun 29, 2016

    @PatrickJS
    Contributor

    for webpack use angular2-template-loader. it's setup in the universal-starter

  24. davidthor commented on Jun 29, 2016

    @davidthor

    Thanks for the response @gdi2290. I'm realizing now that I might be looking at the problem wrong if the resolution is as simple as that. I started from the universal-starter and thus have angular2-template-loader in place, but didn't want to be stuck leveraging the router-deprecated, so I updated to the latest and made the relevant modifications to the route configuration. I thought I had read elsewhere that the latest version of angular-universal was supportive of the new router, but it's possible that my issues are related to those updates instead of explicitly to the templateUrl locations. I may have leapt to conclusions since I was experiencing errors server-side but not client-side.

  25. PatrickJS commented on Jun 30, 2016

    @PatrickJS
    Contributor

    track #432 for runtime styleUrls. for runtime templateUrl provide __filename for moduleId

  26. angular-automatic-lock-bot commented on Sep 4, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  27. locked and limited conversation to collaborators on Sep 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions