Skip to content
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

Base URL support in templates and stylesheets #2384

Closed
mhevery opened this issue Jun 5, 2015 · 14 comments
Closed

Base URL support in templates and stylesheets #2384

mhevery opened this issue Jun 5, 2015 · 14 comments
Assignees
Labels
breaking changes effort2: days feature Issue that requests a new feature
Milestone

Comments

@mhevery
Copy link
Contributor

mhevery commented Jun 5, 2015

GOAL

Add support to the template/stylesheets for base URL so that components can refer to resources in relative paths.

Problem

-- components
  +-- zippy.ts
  +-- zippy.html
  +-- zippy.css
  +-- zippy.gif

where:

zippy.ts

@Component()
@View({
  moduleId: module.id, // see #2383
  templateUrl: 'zippy.html',
  styleUrls: ['zippy.css']
})
class Zippy {}

zippy.html

...
<!-- THIS WILL NOT WORK -->
<img src="zippy.gif">

<!-- WE NEED TO SUPPORT THIS -->
<img src="$baseUrl/zippy.gif">
...
selector {
  backround-url: 'zippy.gif', # DOES NOT WORK
  backround-url: '$baseUrl/zippy.gif', # WORKS
}

Why prefix $baseUrl and not do it automatically?

We need to mark attributes that take relative urls in html files explicitly, as we don't know which attributes are urls and which ones are not.
Also, in html files we could have something like <img src="$baseUrl/{{img}}.gif">

Solution

@rolandjitsu
Copy link

Will this solve the issue of resolving the path for a template relative to the component instead of writing the full path?
E.g.:

@Component({
    selector: 'app'
})
@View({
    templateUrl: 'components/app/app.html',
    directives: []
})
class App {}

vs.

@Component({
    selector: 'app'
})

@View({
    templateUrl: './app.html',
    directives: []
})
class App {}

@mhevery mhevery modified the milestone: M11 Jun 8, 2015
@mhevery
Copy link
Contributor Author

mhevery commented Jun 9, 2015

@rolandjitsu you are looking for #2383

@mhevery
Copy link
Contributor Author

mhevery commented Jun 9, 2015

FYI @vicb updated the description

@mhevery mhevery added feature Issue that requests a new feature effort2: days comp: core/view/compiler labels Jun 9, 2015
@rolandjitsu
Copy link

@mhevery thanks, both this one and the other you pasted are great ideas :)

@rolandjitsu
Copy link

@mhevery I just had a thought while playing with components. Whenever I load a stylesheet within a template using <style>@import "app.css";</style>, I experience some flickering. I suppose that is due to the delay of the stylings being loaded and then applied to the DOM.

If so, the current proposal, will it fix this issue? Otherwise may I suggest delaying DOM injection until the styles have been loaded to avoid this flickering (there is a very obvious delay, e.g. the text is black for a few milliseconds and then suddenly it changes to the color the styling says it should be)?

@mhevery
Copy link
Contributor Author

mhevery commented Jun 12, 2015

@rolandjitsu see #1694

@vicb
Copy link
Contributor

vicb commented Jun 17, 2015

@rolandjitsu

I experience some flickering

This will be fixed with by #2563 fixing #1694

@vicb
Copy link
Contributor

vicb commented Jun 17, 2015

@mhevery do we actually need this for css ? we already resolve url(...) and url('./path') is much nicer than '$baseUrl/path' IMO.

@naomiblack naomiblack modified the milestones: alpha-29, alpha-28 Jun 18, 2015
@vicb
Copy link
Contributor

vicb commented Jul 1, 2015

As indicated in my comment above, I'm not sure if this issue makes sense for styles. Html should be enough.

@vicb vicb removed their assignment Jul 1, 2015
@naomiblack naomiblack modified the milestones: alpha-31, alpha-29 Jul 1, 2015
@naomiblack
Copy link
Contributor

@tbosch can you pick this one up from @vicb or reassign?

@tbosch tbosch modified the milestone: alpha-31 Jul 11, 2015
@naomiblack naomiblack added this to the alpha-32 milestone Jul 13, 2015
@alxhub
Copy link
Member

alxhub commented Jul 16, 2015

I've determined how I'm going to do this - $basePath will be string-replaced into the HTML string during ViewLoader._loadHtml with the relative base path of the template file (if loaded from a template URI) or the component (if the template is inlined).

alxhub added a commit to alxhub/angular that referenced this issue Jul 17, 2015
…mplate.

Angular fetches template HTML files outside of the browser's normal parsing flow. As a result, URLs in template files are interpreted relative to the root application, when the components defined by the template files are inserted into the DOM. This change enables a template author to prefix URLs with the string $baseUrl, which will be replaced with the relative base path of the template file.

So for an example template loaded from /component/foo/template.html:

<img src="$baseUrl/logo.png" />

becomes:

<img src="/component/foo/logo.png" />

Addresses angular#2384.
alxhub added a commit to alxhub/angular that referenced this issue Jul 17, 2015
…mplate.

Angular fetches template HTML files outside of the browser's normal parsing flow. As a result, URLs in template files are interpreted relative to the root application, when the components defined by the template files are inserted into the DOM. This change enables a template author to prefix URLs with the string $baseUrl, which will be replaced with the relative base path of the template file.

So for an example template loaded from /component/foo/template.html:

<img src="$baseUrl/logo.png" />

becomes:

<img src="/component/foo/logo.png" />

Addresses angular#2384.
alxhub added a commit to alxhub/angular that referenced this issue Jul 17, 2015
…mplate.

Angular fetches template HTML files outside of the browser's normal parsing flow. As a result, URLs in template files are interpreted relative to the root application, when the components defined by the template files are inserted into the DOM. This change enables a template author to prefix URLs with the string $baseUrl, which will be replaced with the relative base path of the template file.

So for an example template loaded from /component/foo/template.html:

<img src="$baseUrl/logo.png" />

becomes:

<img src="/component/foo/logo.png" />

Addresses angular#2384.
alxhub added a commit to alxhub/angular that referenced this issue Jul 20, 2015
…mplate.

Angular fetches template HTML files outside of the browser's normal parsing flow. As a result, URLs in template files are interpreted relative to the root application, when the components defined by the template files are inserted into the DOM. This change enables a template author to prefix URLs with the string $baseUrl, which will be replaced with the relative base path of the template file.

So for an example template loaded from /component/foo/template.html:

<img src="$baseUrl/logo.png" />

becomes:

<img src="/component/foo/logo.png" />

Addresses angular#2384.
alxhub added a commit to alxhub/angular that referenced this issue Jul 20, 2015
…mplate.

Angular fetches template HTML files outside of the browser's normal parsing flow. As a result, URLs in template files are interpreted relative to the root application, when the components defined by the template files are inserted into the DOM. This change enables a template author to prefix URLs with the string $baseUrl, which will be replaced with the relative base path of the template file.

So for an example template loaded from /component/foo/template.html:

<img src="$baseUrl/logo.png" />

becomes:

<img src="/component/foo/logo.png" />

Addresses angular#2384.
alxhub added a commit to alxhub/angular that referenced this issue Jul 20, 2015
…mplate.

Angular fetches template HTML files outside of the browser's normal parsing flow. As a result, URLs in template files are interpreted relative to the root application, when the components defined by the template files are inserted into the DOM. This change enables a template author to prefix URLs with the string $baseUrl, which will be replaced with the relative base path of the template file.

So for an example template loaded from /component/foo/template.html:

<img src="$baseUrl/logo.png" />

becomes:

<img src="/component/foo/logo.png" />

Addresses angular#2384.
alxhub added a commit to alxhub/angular that referenced this issue Jul 20, 2015
…mplate.

Angular fetches template HTML files outside of the browser's normal parsing flow. As a result, URLs in template files are interpreted relative to the root application, when the components defined by the template files are inserted into the DOM. This change enables a template author to prefix URLs with the string $baseUrl, which will be replaced with the relative base path of the template file.

So for an example template loaded from /component/foo/template.html:

<img src="$baseUrl/logo.png" />

becomes:

<img src="/component/foo/logo.png" />

Addresses angular#2384.
alxhub added a commit to alxhub/angular that referenced this issue Jul 20, 2015
…mplate.

Angular fetches template HTML files outside of the browser's normal parsing flow. As a result, URLs in template files are interpreted relative to the root application, when the components defined by the template files are inserted into the DOM. This change enables a template author to prefix URLs with the string $baseUrl, which will be replaced with the relative base path of the template file.

So for an example template loaded from /component/foo/template.html:

<img src="$baseUrl/logo.png" />

becomes:

<img src="/component/foo/logo.png" />

Addresses angular#2384.
alxhub added a commit to alxhub/angular that referenced this issue Jul 20, 2015
…mplate.

Angular fetches template HTML files outside of the browser's normal parsing flow. As a result, URLs in template files are interpreted relative to the root application, when the components defined by the template files are inserted into the DOM. This change enables a template author to prefix URLs with the string $baseUrl, which will be replaced with the relative base path of the template file.

So for an example template loaded from /component/foo/template.html:

<img src="$baseUrl/logo.png" />

becomes:

<img src="/component/foo/logo.png" />

Addresses angular#2384.
alxhub added a commit to alxhub/angular that referenced this issue Jul 20, 2015
…mplate.

Angular fetches template HTML files outside of the browser's normal parsing flow. As a result, URLs in template files are interpreted relative to the root application, when the components defined by the template files are inserted into the DOM. This change enables a template author to prefix URLs with the string $baseUrl, which will be replaced with the relative base path of the template file.

So for an example template loaded from /component/foo/template.html:

<img src="$baseUrl/logo.png" />

becomes:

<img src="/component/foo/logo.png" />

Addresses angular#2384.
alxhub added a commit to alxhub/angular that referenced this issue Jul 20, 2015
…mplate.

Angular fetches template HTML files outside of the browser's normal parsing flow. As a result, URLs in template files are interpreted relative to the root application, when the components defined by the template files are inserted into the DOM. This change enables a template author to prefix URLs with the string $baseUrl, which will be replaced with the relative base path of the template file.

So for an example template loaded from /component/foo/template.html:

<img src="$baseUrl/logo.png" />

becomes:

<img src="/component/foo/logo.png" />

Addresses angular#2384.
alxhub added a commit that referenced this issue Jul 20, 2015
…mplate.

Angular fetches template HTML files outside of the browser's normal parsing flow. As a result, URLs in template files are interpreted relative to the root application, when the components defined by the template files are inserted into the DOM. This change enables a template author to prefix URLs with the string $baseUrl, which will be replaced with the relative base path of the template file.

So for an example template loaded from /component/foo/template.html:

<img src="$baseUrl/logo.png" />

becomes:

<img src="/component/foo/logo.png" />

Addresses #2384.
@alxhub alxhub closed this as completed Jul 21, 2015
@adamduren
Copy link

Does this feature still exist? I tried it in a component I am building and get a 404 with the $baseUrl not substituted.

image

@adamduren
Copy link

@alxhub

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking changes effort2: days feature Issue that requests a new feature
Projects
None yet
Development

No branches or pull requests

7 participants