TemplateURL - Relative Path not resolving.

See original GitHub issue

I’m submitting a … (check one with “x”)

[X] bug report => search github for a similar issue or PR before submitting

Current behavior With the latest version of Angular 4.1.3, we need to use Relative URL’s for TemplateURL on the components.

These components are being used within an Angular Library I am building. The library compiles and is then referenced as a dependency in a new application.

Here is the old code I had within a Nav.Component :

@Component({
  selector: 'navigation',
  templateUrl: 'app/components/nav.component.html',
  styleUrls: ['app/components/nav.component.css'],
  providers:[CredentialManagementService]    
})

New Proposed Code:

@Component({
  selector: 'navigation',
  templateUrl: './nav.component.html',
  styleUrls: ['./nav.component.css'],
  providers:[CredentialManagementService]    
})

However I am getting the following error:

:3000/nav.component.html Failed to load resource: the server responded with a status of 404 (Not Found)

Expected behavior The path should route correctly to nav.component.html which is in the same folder as the nav.component.ts file.

Minimal reproduction of the problem with instructions Since we are building a library which isn’t quite yet finished, it is quite hard to reproduce a plunker for another another environment.

However hopefully someone will have some guidance/help with how the new TemplateURL’s work. As you can see from the above example, we have a standard typescript component which is referencing a html template. The directory is similar to this:

app

components

nav.component.ts nav.component.html**

So I need to reference the ‘nav.component.html’ as a templateURL within ‘nav.component.ts’. Both of these files are in the same folder.

What is the motivation / use case for changing the behavior? Upgrading to the latest version of Angular 4.1.3. Ideally need to use relative paths in the URL as absolute paths / module.id are now deprecated.

Please tell us about your environment: Windows 7. Visual Studio Code.

  • Angular version: 4.1.3

  • Browser: [Chrome v58 ]

  • Language: [Typescript 2.3 / ES6]

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

12reactions
darincardincommented, Jun 5, 2017

The answer is: don’t use angular 2. It is extremely bug prone, especially the more advanced stuff. Don’t even try to configure AOT. I know this is not the answer you wanted. Trust me, its not the answer I wanted. But it is simply not stable at this point.

6reactions
rydergillen-compacSortcommented, Oct 30, 2017

/Agree… the DEV overhead required for getting a BASIC Angular working is a complete joke. The 1200+ open bugs should have been a red flag

Read more comments on GitHub >

github_iconTop Results From Across the Web

Stating directive templateUrl relative to root - Stack Overflow
This works fine: templateUrl: '/Scripts/app/templates/personalDetails.html' ... Then keep your template paths relative to this, as in
Read more >
path in templateUrl changes to path relative to current file on ...
When working in a different project configuration, where the template has no path at all (because it's relative and in same folder as...
Read more >
Angular 2 — Component Relative URL Paths - Medium
When I initially started working with Angular 2, (it seemed to me anyway) that these properties had to be loaded from absolute url...
Read more >
Relative path not working in global partial - HubSpot Community
Solved: I am developing a theme that I want to submit to marketplace. I have a few custom DND modules in my footer,...
Read more >
Angular2 relative paths for templateUrl and styleUrls - iTecNote
Modified coding (Not working due to incorrect path) – @Component({ selector: 'class-timing', templateUrl: 'class-timing.html', moduleId: module.id, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found