1

I set up a new project using "ng new xxx", just add one line in index.html:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Bbb</title>
  <base href="/">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">

</head>
<body>
  <app-root></app-root>
 <script type="text/javascript" src="./CitrixHTML5SDK.js"></script>
</body>
</html>

Then put the JS file in the same dir as index.html

the same dir

But when I run "ng server", the browser always show: 404

the js file not found

Does anyone know why? Thanks in advance.

2
  • I believe that you can't simply place an external js file out of the project scope and expect it to work. Commented Nov 14, 2017 at 4:34
  • @KevinRED check my answer hope it will work :) Commented Nov 14, 2017 at 4:44

2 Answers 2

1

I was going through same issue with JSON file, so what I done is kept my JSON file in to assets folder. And access it through my code.

Here in Project file review you can also verify it.

Sign up to request clarification or add additional context in comments.

Comments

0

If you want to create a new folder i.e. "data". Then you will have to add "data" in "assets" array of angular-cli.json file. See below JSON data :-

    "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "data",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app",
      "styles": [
        "styles.css"
      ],
      "scripts": ["data/sample.js"],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],

After that don't forget to restart the server. Otherwise you will get 404 error.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.