Angular2导入路径错在运行时 [英] Angular2 import path wrong at runtime
问题描述
我有一个angular2应用程序,并在运行时,它会尝试从错误的URL加载资源。
I have an angular2 app and at runtime it tries to load a resource from the wrong URL.
应该寻找它在:
的http://本地主机:54675 /应用程序/服务/ angular2-jwt.js ,但看起来它在:
的http://本地主机:54675 /应用/ 共享 /服务/ angular2,智威汤逊.js文件。共享这个词不应该是在路径中。
It should look for it at: http://localhost:54675/app/services/angular2-jwt.js, but it looks for it at: http://localhost:54675/app/shared/services/angular2-jwt.js. The word shared should not be in the path.
我在angular2此结构:
I have this structure in angular2:
app
---services
------angular2-jwt.ts
---shared
------country
---------country.service.ts
在country.service.ts我引用angular2-jwt.ts是这样的:
In country.service.ts I reference angular2-jwt.ts like this:
import {AuthHttp} from '../../services/angular2-jwt';
正如你所看到的,这是两个(进入应用程序),并分解成服务。它应该给这个路径:应用程序/服务/ angular2,智威汤逊。
我期待在长相编译JS纠正:
As you can see, that's up two (into app) and down into services. It should give this path: app/services/angular2-jwt. I look in the compiled js at looks correct:
System.register(['angular2/core', '../../services/angular2-jwt']
我使用Visual Studio和智能感知的作品。我看到AuthHttp在弹出从该库的选项。当我保存或建立我没有得到一个错误。我认为这是正确的。
I am using Visual Studio and the intelliSense works. I see AuthHttp in a popup as an option from that library. I don't get an error when I save or build. I think this is correct.
在运行时,我得到了broswer控制台这个错误:
At runtime I get this error in the broswer console:
Error: Unable to load script: http://localhost:54675/app/shared/services/angular2-jwt.js
注意脚本URL路径是错误的。据共享作为路径的一部分,但不应该。
Notice the script URL path is wrong. It has 'shared' as part of the path but should not.
我在缓存我的浏览器禁用。我看在浏览器中的js源和我看到相同的源如上所述。它发生在铬(我的默认)和Firefox(我很少使用),所以我不认为这是一个缓存的问题。它是如何得到这条道路?
I have caching disabled in my browser. I look at the js source in the browser and I see that same source mentioned above. It happens in chrome (my default) and Firefox (which I rarely use) so I don't think it's a caching issue. How is it getting this path?
下面是我从SystemJS的index.html configuraiton:
Here is my SystemJS configuraiton from index.html:
<script>
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
}
}
});
System.import('app/boot')
.then(null, console.error.bind(console));
</script>
现在我已经重复这另一台机器上。不过,我从不同的文件中以类似locaiton导入此相同的模块('../../services/angular2-jwt')是目录树和它的作品。
I have now duplicated this on another machine. However, I am importing this same module ('../../services/angular2-jwt') from a different file at a similar locaiton is the directory tree and it works.
推荐答案
检查导入路径的所有组件,不只是这一个。我在一个父组件有语法错误,并导致出现此问题。
Check the import path to all components, not just this one. I had bad syntax in a parent component and it caused this issue.
这篇关于Angular2导入路径错在运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!