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

Template cache generator doesn't resolve templates the same way angular does. #750

Closed
bgourlie opened this issue Mar 18, 2014 · 3 comments
Closed
Milestone

Comments

@bgourlie
Copy link
Contributor

The template_cache_generator isn't properly resolving templates. For example, I have
/lib/my_library.dart
/lib/src/components/chat_view.dart
/lib/src/components/chat_view.html
/web/entrypoint.dart

In chat_view.dart I'm specifying the templateUrl as follows:
templateUrl: 'packages/my_library/src/components/chat_view.html

I notice the generator looks for the templates relative to the directory that contains the library file. In the case of the above configuration, it's looking for the template in /lib/packages/my_library/src/components/chat_view.html.

Prior to 0.9.9, this configuration was working. I would expect the template cache generator look for templates relative to the entrypoint file, which if using proper conventions should be the web directory. Instead, it's looking for them relative to my library that was imported in the entrypoint.

I did some initial digging into recent changes but couldn't find the culprit. I'll keep looking in the meantime.

@bgourlie
Copy link
Contributor Author

This commit is the culprit: f918d4d

I'm unable to specify a templateUrl that both angular can resolve at runtime and the template_cache_generator can resolve.

@TedSander
Copy link
Contributor

tl;dr; Simple fix would be to change the URL to an absolute URL. /packages/my_library/src/components/chat_view.html/

Commit f918d4d was a fix to start processing parts of library definitions. Prior to this the /lib/src/components/chart_view.dart wasn't being processed. So while the template generator was running I don't think it was adding it to the template cache.

Now that the component is being processed the system thinks the file path is relative. For path relative URIs it uses the src component to determine the relative path, but this is problematic as it is relative to the current source and not context URI. That being said context URI would be pretty hard to determine when generating the cache. Imagine a simple component that was used multiple locations. What would be the correct URI to determine the relative path? It would change depending on where the component was used. Unless it should always be root relative then I would argue absolute paths should be used to indicate this.

For this reason components in the lib directory should be absolute urls pointing at the packages directory /packages/... or made absolute using the regex rewriters in the template generator.

Your component works in angular as long as your context url path is root. Some relative URLs would work in the component was in the web directory depending on the context being used, but I largely avoid them. Some work is being done currently to allow you to use relative URIs from the component which would be much more useful in my opinion.

@bgourlie
Copy link
Contributor Author

bgourlie commented Apr 8, 2014

The fix you propose only works when running the app normally. The template cache generator still fails to resolve it.

@mhevery mhevery assigned blois and unassigned pavelgj Apr 10, 2014
@mhevery mhevery added this to the 0.9.11 milestone Apr 10, 2014
@vicb vicb modified the milestones: 0.10.0, 0.9.11 Apr 16, 2014
@mhevery mhevery modified the milestones: 0.12.0, 0.10.0 Apr 17, 2014
@vicb vicb modified the milestones: 0.12.0, 0.11.0 May 8, 2014
@chirayuk chirayuk modified the milestones: 0.13.0, 0.12.0 Jun 3, 2014
@vsavkin vsavkin modified the milestones: 0.14.0, 0.13.0 Jul 24, 2014
@rkirov rkirov modified the milestones: 0.14.0, 0.15.0 Aug 22, 2014
@rkirov rkirov closed this as completed Oct 10, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

9 participants