【问题标题】:Angular 9 Typescript referencing node_modules to fix MIME errorAngular 9 Typescript 引用 node_modules 来修复 MIME 错误
【发布时间】:2021-03-25 03:25:50
【问题描述】:

我正在使用 Angular 9 Typescript 构建浏览器应用程序,并尝试实现 webdatarocks 包,以便可以在应用程序的组件中使用数据透视表。我已经安装了 webdatarocks,现在有以下内容:

<!doctype html>
<html lang="en">
<html>
    <head>
        <meta charset="utf-8">
        <link href="/angular-app/node_modules/webdatarocks/webdatarocks.min.css" rel="stylesheet"/>
        <script src="/angular-app/node_modules/webdatarocks/webdatarocks.toolbar.min.js"></script>
        <script src="/angular-app/node_modules/webdatarocks/webdatarocks.js"></script>
        <base href="/">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="icon" type="image/x-icon" href="favicon.ico"> 
    </head> 
    
    <body>
        <app-wbr-pivot #pivot1 [toolbar]="true">
         Webdatarocks will appear here
        </app-wbr-pivot>
    </body>
</html>

请注意,这不是 index.html 文件。该文件是独立的,包含整个应用程序的样式等,我试图仅在应用程序的一个组件中使用 webdatarocks,因此上述代码位于组件的 html 文件中。 (不确定是否建议这样做,因为我对此很陌生,但我不明白为什么它不应该工作?)。尝试运行此程序时,由于以下错误,未应用样式:

Refused to apply style from 'http://localhost:4200/angular-app/node_modules/webdatarocks/webdatarocks.min.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

现在我知道这可能不起作用,因为它无法匹配到 url 的任何路由,因此它被读取为 html 中的错误页面,而不是 css 文件。我的问题是如何实际解决这个问题?我是否必须以某种方式将此网址添加到路由模块?有没有办法简单地指向 node_modules 中所需的库?我尝试添加

"./node_modules/webdatarocks/webdatarocks.min.css"
"./node_modules/webdatarocks/webdatarocks.toolbar.min.js",
"./node_modules/webdatarocks/webdatarocks.js"

到 angular.json 文件中的样式和脚本,它仍然不起作用。

谢谢,如果我能澄清任何事情,请告诉我!

【问题讨论】:

  • 这能回答你的问题吗? How to include script to head in angular.json
  • 嘿,philipp,感谢您的回复,但不完全是,仔细检查该链接,脚本似乎没问题,因为数据透视表似乎可以工作,主要问题是样式未应用

标签: html css angular typescript node-modules


【解决方案1】:

好的,我知道我所要做的就是删除 head 标签中的所有内容,然后添加:

@import "webdatarocks/webdatarocks.min.css";

到 styles.css 文件,其余的由 Angular 处理。

【讨论】:

    猜你喜欢
    • 2021-07-02
    • 1970-01-01
    • 2021-01-12
    • 2020-10-16
    • 2020-06-04
    • 2021-04-19
    • 1970-01-01
    • 2019-07-12
    相关资源
    最近更新 更多