代码之家  ›  专栏  ›  技术社区  ›  Vimal

将脚本从本地文件夹加载到组件时出现404错误

  •  -1
  • Vimal  · 技术社区  · 5 年前


    enter image description here

    404错误 enter image description here


    波形虫

    1 回复  |  直到 5 年前
        1
  •  0
  •   Sunil Kashyap    5 年前

    当您为angular应用程序提供服务时,它会在端口4200启动带有目录的服务器 PROJECT_FOLDER/src 当您在组件中加载脚本时,它已经在src文件夹中了,所以只需使用 app/shared/... 而不是 src/app/shared/...

        2
  •  0
  •   Nadhir Falta    5 年前

    我认为Angular会将这些文件视为静态文件,这意味着它们不会在编译时加载,而是在运行时加载,并且在运行时 /src assets (或者你要求Angular从 src .

    1-将静态文件移动到asstes中,然后可以将它们引用为 /assets/payment/js/init-payment.js .

    2-要求Angular在编译时将特定目录从src复制到build目录。 angular.json 文件在 资产
    有关详细信息,请参见以下答案:

    Whats the default path for static files in Angular2?