Reputation: 53
I am creating small angular application in which I have placed app.js in my application folder where index.html is also there. When, I run 'ng serve' command then index.html is loading but while doing F12 on chrome there it is showing up below error: GET http://localhost:4200/app.js net::ERR_ABORTED 404 (Not Found)
my index.html file:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>GridDemo</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<script src="app.js"></script>
</head>
<body>
<app-root></app-root>
</body>
</html>
Even though adding <base href="/"></base>
is not making any impact.
Upvotes: 4
Views: 12453
Reputation: 872
Being a bit more specific to what @David said, the js file needs to be included within a folder defined as an asset in the angular.json file. If you created the app with the cli, an "assets" folder should have been setup that way by default. So, I'd expect something like: <script src="assets/js/app.js"></script>
The exact property in the angular.json is projects.${app-name}.architect.build.options.assets and takes an array of strings.
But as to what @Harini P said, it is recommended to not do any dom changes outside of the regular angular file structure.
Upvotes: 7