admin管理员组文章数量:1391943
I have added a local javascript file with <script type='text/javascript' src='Test.js'>
in my index.html, but when I run it with ng serve and go to localhost:4200
, in my browser console I see this error:
GET localhost:4200/Test.js 404 (Not Found) but I do have my file in the same location that my index.html.
but angular 2 not loading or finding this. Please help me.
I have added a local javascript file with <script type='text/javascript' src='Test.js'>
in my index.html, but when I run it with ng serve and go to localhost:4200
, in my browser console I see this error:
GET localhost:4200/Test.js 404 (Not Found) but I do have my file in the same location that my index.html.
but angular 2 not loading or finding this. Please help me.
Share Improve this question edited Jun 25, 2017 at 15:09 Saurabh Bhandari 2,4584 gold badges28 silver badges33 bronze badges asked Jun 24, 2017 at 20:26 Vidhya SagarVidhya Sagar 331 silver badge11 bronze badges 3- What error do you get... – Juan Commented Jun 24, 2017 at 20:29
- GET localhost:4200/Test.js 404 (Not Found) I get this error. – Vidhya Sagar Commented Jun 24, 2017 at 20:30
- 1 Wele to Stalk Overflow. Update that as part of your question before you get a wave of downvotes. See this: stackoverflow./help/how-to-ask. And when you get an answer that is acceptable to you, don't forget to mark it as so: stackoverflow./help/someone-answers. – Juan Commented Jun 24, 2017 at 20:40
1 Answer
Reset to default 8Move your Test.js
file to the assets folder.
Then from index.html
, point to that folder <script type='text/javascript' src='./assets/Test.js' >
WHY?
When you serve your app with ng serve
, there's a structure set for it. If you want to see it, run ng build
, you will see a dist
folder being created.
Observe the assets folder gets move to that dist folder, and that's how the app expects it. So you are getting the not found error because from the server's perspective, there's no such file there.
When you make those changes and run ng serve
, things should work and error should go away.
Hope this is of help.
本文标签: My Local JavaScript file is not loaded in Angular 2Stack Overflow
版权声明:本文标题:My Local JavaScript file is not loaded in Angular 2 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744683277a2619544.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论