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

How to use css variable from CDN file in angular 6? #46

Closed
sga-girdhari opened this issue Dec 17, 2018 · 6 comments
Closed

How to use css variable from CDN file in angular 6? #46

sga-girdhari opened this issue Dec 17, 2018 · 6 comments
Labels

Comments

@sga-girdhari
Copy link

sga-girdhari commented Dec 17, 2018

Hi @jhildenbiddle ,

I am trying to use this library in one of my angular 6 project, which is using CSS variable from a file coming from CDN (due to theme implementation, I can switch theme/files dynamically).

But I am getting CORS issue on IE, and warning on chrome/other browsers regarding undefined variable (I will set onlyLegacy to true though).

Can you please help me, in loading file from CDN on angular 6 project.

Please see attached snapshot.
image

Thanks.

@jhildenbiddle
Copy link
Owner

jhildenbiddle commented Dec 17, 2018

Hi @sga-girdhari,

The errors you are receiving indicate that the CDN server you are using is not CORS-enabled. Specifically, the CDN server is not setting the appropriate response headers that allow the ponyfill to request <link> stylesheets via XMLHttpRequest (aka "AJAX"). This is required in order for the ponyfill to work, as it is the only way the ponyfill can read the CSS content of the linked stylesheet.

If possible, switch to a CDN that is already CORS-enabled. If this is not possible, consider hosting the CSS file locally (on the same server as your app). Either one of these options will (presumably) also resolve the undefined variable warnings you are seeing in the console as well.

@sga-girdhari
Copy link
Author

Hi @jhildenbiddle ,

Thanks for replying so quickly, I am doing it locally for now, but will try to enable CORS on CDN server.

Thanks.

@sheikalthaf
Copy link

sheikalthaf commented Jan 22, 2019

@sga-girdhari @jhildenbiddle Hi,

I'm planning to implement this ponyfill to angular 7 project. but var it is only working for app.component file.
for other component it is not working. anything I'm missing here in angular project

@sga-girdhari
Copy link
Author

Hi @sheikalthaf,
From where are you are calling cssVars method, I would suggest to do it from main.ts file. And it should work for you irrespective of your component (as per my understanding) variables are replaced on runtime.

Thanks.

@sheikalthaf
Copy link

sheikalthaf commented Jan 22, 2019

@sga-girdhari Thanks. I have placed the cssVars in themeService in root.

cssVars({
      rootElement: element,
      onlyLegacy: false,
      onlyVars: true,
      variables: theme.properties,
      watch: true,
      onComplete: (a, b, variables) => {}
    });

@jhildenbiddle if i enable watch then styles get applied but IE browser hangs for a while and then restored.
how you handling this in your angular app?

@jhildenbiddle
Copy link
Owner

@sheikalthaf,

Best to create a new issue since this one is closed.

Before you do that, understand that I'm not sure how much help I can provide without seeing the CSS involved. Consider creating a demo project that is configured like yours so others can review and make suggestions. I have found codesandbox.io and stackblitz.com useful for such tasks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants