You need to sign in to do that
Don't have an account?
Surya Chandra Rao Gandreddi
Load Fonts in Component
I'm trying to load fonts (dynamically) from the static resource,
The fonts are not loading, but if I hard code the same in the component they work fine. Am I missing something?
Fonts are loaded (from an AuraEnabled controller Method) on onInit which calls addFont.
addFont: function(name, link) { var css = '@font-face { font-family: ' + name + '; src: url("' + link + '");'; console.log('addFont css: ', css); var head = document.head || document.getElementsByTagName('head')[0]; var style = document.createElement('style'); style.type = 'text/css'; if (style.styleSheet){ style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); } head.appendChild(style); }
The fonts are not loading, but if I hard code the same in the component they work fine. Am I missing something?
Fonts are loaded (from an AuraEnabled controller Method) on onInit which calls addFont.
In your case font files are already available as static resources. So you can create the font families in advance (inside CSS file) and only change the fontFamily property dynamically through JavaScript action. Here is an example.
Component: CSS File: JS Controller: Thanks,
Nagendra