【发布时间】:2023-03-04 12:42:01
【问题描述】:
我必须使用在其他地方定义的 scss,才能在我的 @Injectable 类中使用
import { Injectable } from '@angular/core';
const customThemeRed = require('../../common/styles/custom/themes/custom-theme-red.scss');
@Injectable()
export class MyThemesService {
constructor() {
console.log('customThemeRed is' + customThemeRed);
}
...
由于某种原因,即使我通过 NodeJS 'require' var 导入,我也无法使用这个 scss。我可以知道如何导入外部 JS/SCSS 文件
【问题讨论】:
-
您可以将它们添加到常量文件中,然后引用
constants.ts文件。将自定义样式作为对象返回:custom_theme_red = { background: 'red' }..您可以将它们应用到引用ElementRef内的 NativeElement 的组件中 -
我认为您指的是使用简单的 key-val 对,或者我可能误解了!我想使用整个 SCSS 文件并将其作为变量传递来设置我的 document.style [动态]。这样,想改变整个应用程序的主题。但是使用require,我的SCSS没有被导入,但是可以导入一个普通的CSS文件
标签: javascript angular sass