2

I am working on multi tenant application in angular. For that am trying to apply css from different clients @import url('http://myserver/themes/ABC/css/component1.css');

@import url('http://myserver/themes/DEF/css/component1.css');

I want client name to be fetched from ts file and then import corresponding css.How can I do that?Please help me

1 Answer 1

0

Old question, but I came across this today looking for the same thing. In the end, adding an external stylesheet is easiest done by simple DOM manipulation:

  addImport(url: string): void  {
    const linkElement = document.createElement('link');
    linkElement.rel = 'stylesheet';
    linkElement.href = url;
    linkElement.id = this.importedFontUrlStyleId;
    document.head.appendChild(linkElement);
  }

I'm setting this.importedFontUrlStyleId here so later I can remove the stylesheet with

const importedFontSheet = document.head.querySelector(`#${this.importedFontUrlStyleId}`);
if (importedFontSheet) {
  document.head.removeChild(importedFontSheet);
}  

The security risk of importing a variable stylesheet should be obvious.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.