Angular2无法加载boot.js

时间:2016-05-31 11:38:08

标签: angular

当我直接从file:///C:/wamp/www/ngProject/index.html或从wamp:http://localhost/ngproject/

运行时,我无法传递boot.js文件

在开发模式下,它适用于npm-start,但不应该使用WAMP或只运行Index.html吗?

这是我的system.js

  <script>
  System.config({
    packages: {        
      app: {
        format: 'register',
        defaultExtension: 'js'
      }
    }
  });
  System.import('app/boot')
        .then(null, console.error.bind(console));
</script>

从wamp开始时 - 错误:无法加载脚本http://localhost/app/boot.js加载http://localhost/app/boot.js时出错 启动Index.html 时出错 - 错误:无法加载脚本文件:///app/boot.js     加载文件时出错:///app/boot.js

3 个答案:

答案 0 :(得分:1)

基本上,你总是需要一个http服务器来运行Angular应用程序。

看看这个问题。关于为什么需要http服务器,有一些非常可靠的答案。

Why do I need a HTTP-server to run Angular 2?

此致

答案 1 :(得分:0)

尝试检查boot.js的路径。从wamp开始时 - 错误:无法加载脚本http://localhost/app/boot.js

Error loading http://localhost/app/boot.js

此处的路径似乎是错误的,因为您的js文件位于

@ http://localhost/ngProject/app/boot.js

这样的事可能会让你感到害怕

对于wamp服务器,请尝试

 System.config({
            baseURL: 'ngProject'
        });

System.import('app/boot')
        .then(null, console.error.bind(console));

答案 2 :(得分:0)

因此,当您使用npm-start时,您的项目可能会为您的种子设置服务器。这将包含在种子包中运行的服务器的所有配置设置。

如果您使用了我喜欢的angular2-seed,但其选项可能略显复杂,设置如下:tools / config / seed-config.ts

这样做是MAP到你的根文件夹来加载文件。

默认情况下,Wamp会将localhost映射到c:\www,但您确实希望它映射到c:\www\ngProject

这样想,

加载/ngProject/index.html时 它说,“好的,我需要加载位于/app/boot.js

的boot.js

但它真的在/ngProject/app/boot.js并且失败了

您可以在所有配置中更改系统以从/ ngProject加载,或者我推荐的是调整您的wamp设置。

来自this SO Answer:

的说明

对于Windows上的wamp 2.5,请使用文本编辑器,例如notepad ++编辑c:\ wamp \ bin \ apache \ apache2.4.9 \ conf \ httpd.conf

  1. 将DocumentRoot“c:/ wamp / www”更改为DocumentRoot“c:/ my / new / path” (注意斜线方向)。这将改变文件的位置 从(~230行)送达。
  2. 转到      (注意斜线方向)。这适用     从旧目录到新目录的权限(〜第252行)。
  3. 另一件事是,许多种子也有一个“生产”版本,它将自动转换为相对/基本根路径结构。这也是我要检查的东西..

相关问题