0

I have to load css according to some parameters, that come from backend. If RoleID is 1 then I want to load role1.scss and for RoleID is 2 then I want to load role2.scss. Here i'm taking css files path from backend.This selected css should apply to the whole application.

In component I have written this.document.getElementById('theme').setAttribute('href', this.cssLink ); this.cssLink is the path of css file taken from backend

In my index.html

<link id="theme" href="styles.scss">

I have also tried

 require('style-loader!' + this.cssLink);

It gives error: Error: Cannot find module 'style-loader!src/app/role1.scss'

1 Answer 1

1

Try this one

function loadcssfile(filename) {
    var fileref = document.createElement("link")
    fileref.setAttribute("rel", "stylesheet")
    fileref.setAttribute("type", "text/css")
    fileref.setAttribute("href", filename)
    document.getElementsByTagName("head")[0].appendChild(fileref)
}

loadcssfile("here your css file path", "css");
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.