-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[question] Support for image/font relative paths in css #6637
Comments
Just to save the trouble of reading the whole referenced issue, you need to set the 'moduleId' component annotation otherwise it will not work. Available from beta.1
|
The |
So your'e a saying that angular parses the top level assets paths (CSS/HTML) but not their internal content... This is in an essence an implementation of What would be the strategy? Is it going to be a runtime loader or a build loader? interesting issue from many aspects. @pkozlowski-opensource what is the road map on this? clearly its an important issue for those who seek component isolation. For now I guess, you could use a build step to transform these files. Anyway, I'm sure there will be a lot of confusion around A lot of blogs are waiting to be written on the right strategy for the right task on these features. |
This isn't strictly true for |
One more comment: this issue makes it very hard to create components that can be reused across projects that may serve them from different locations. And while the work-around I'm using (inlining using data URLs) is OK, it introduces something I consider to be a production-time optimization into the development workflow. |
I am currently at a roadblock right now, and I don't know how to work around this. I'm trying to use clip-path for SVG, utilizing d3.js, and it will not recognize url("#clip") and I've tried every path I can think of to get it to work with an absolute reference and I still cannot. Really looking to have a solution for html/css relative pathing. |
Just to clarify, there is no solution for referencing images/fonts/whatever inside of CSS by using a relative We also came up with inlining as a "solution" but it doesn't seem like a good fix. This is sort of a big deal for reusable components. |
Any update on this, because it breaks component encapsulation... cant use images or font relative to the component? So how do I encapsulate an <img src="something.svg" with a component has illustrated? dataURLs are not exactly cache friendly. |
Same problem here. Any feedback on what work arounds we could use in RC5? |
Any solutions on this? |
can somebody reproduce in plunkr? |
@DzmitryShylovich please try https://plnkr.co/edit/BfIhk6zsyTmi30cM6Arz?p=preview. At the end of file app/dashboard.component.css there is a reference to a svg file that lives inside app/ folder, although the url has to include app/ to work. |
@mhevery Is the issue relevant? |
will not fix: not feasible. |
@mhevery Why not? See the OP's original question.
Please provide guidance on how this should be handled, or link to the relevant discussion elsewhere so readers can learn why this is no longer supported in Angular. |
@byrondover ... one fact ... external templates and external styles are inlined as the first step of the compilation ... so at that moment there are no externals. |
Because there is no easy way to have the absolute path mean the same thing at runtime (JIT mode) as well as compile (AOT time). |
Thanks for the clarification. For those finding this thread in the future, you can work around this issue by importing relative assets programmatically. Component({
selector: 'app-my-component',
templateUrl: './my.component.html',
styleUrls: ['./my.component.css']
})
export class MyComponent {
headerImageUrl = require('./images/header.png');
} You can then interpolate these variables in your templates as needed. This relies on webpack to resolve the relative path a build time. Injecting variables into CSS styles is even trickier, but also possible. <img class="header-image" src="{{ headerImageUrl }}"> An ugly workaround which pollutes your components with require statements and placeholder variables, but it gets the job done. Here's to hoping for an improved solution at some future date! 🤞 |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I found a few very old issues about this, but the code seems to have been refactored a lot since. (#2384)
I couldn't find any support for this any more.
Example:
my-component.css
Since the css is put into style tags, the browser assumes it's relative to the root, not the
my-component.css
file (or tomy-component.ts
if it's inlined). Also, the host may be different - the files could be served from different domain, and expect the image be requested from the same domain, not the current browser domain.So my question is - is this something that you want to support or should it be handled differently (maybe I missed something)?
The text was updated successfully, but these errors were encountered: