使用 Angular CLI 动态加载 CSS

Tur*_*les 5 css sass angular-cli

我希望能够在我的 Angular 项目中动态加载 CSS。为此,我遵循了本教程中的所有步骤: https://juristr.com/blog/2019/08/dynamically-load-css-angular-cli/

不幸的是,我在下面的 angular.json 中遇到了这个问题:

"dyncss": {
    ...
    "build": {
        ...
        options: {
          ...
          "styles": [
            "src/styles.scss",
            {
              "input": "src/client-a-styles.scss",
              "bundleName": "client-a",
              "inject": false
            },
            {
              "input": "src/client-b-styles.scss",
              "bundleName": "client-b",
              "inject": false
            }
          ],
        }
    },
    ...
},
Run Code Online (Sandbox Code Playgroud)

当我添加行:“inject”:false时,我在这里收到以下错误:

“架构验证失败,出现以下错误:数据路径“.styles[1]”不应具有其他属性(注入)。数据路径“.styles[1]”应为字符串。数据路径“.styles[1]”应为完全匹配 oneOf 中的一个模式”

如果我删除了"inject": falseng build 行,但我必须注入注入才能随后动态加载 css...

ps:角度版本^9.1.3

请,非常欢迎任何帮助!提前致谢!

Jah*_*Can 0

尝试正确更新您的软件包。确保所有软件包都是最新的。我遇到了类似的问题,我忘记更新“ngx-build-plus”以匹配我的角度项目版本。