0

I am trying to migrate a MVC project into Angular 6. I have css files and js files in chtml code which are used in the mvc application as below :

<link rel="stylesheet" href="~/OptumFiles/fonts-clientlibs-global.min.css" type="text/css">
<link rel="stylesheet" href="~/OptumFiles/optum-clientlibs-global.min.css" type="text/css">
<script async="" src="~/OptumFiles/analytics.js"></script>
<script async="" src="~/OptumFiles/js.js"></script>

Now i want to use these files in my angular project globally.

Things i have tried :

  • Created a folder FICAssets in the Angular project.
  • Added files in that folder.
  • Added their reference in index.html file.

Code in index.html :

    <body>
    <link rel="stylesheet" type="css" href="FICAssets/css/fonts-clientlibs-global.min.css">
    <link rel="stylesheet" type="css" href="FICAssets/css/optum-clientlibs-global.min.css">
    <script src="FICAssets/js/analytics.js"></script>
    <script src="FICAssets/js/js.js"></script>
  <app-root></app-root>
</body>

The problem is that iam still not able to load the files , getting 404 error.

enter image description here

2
  • Assets are set in the angular.json file. DId you add it to that file ? Commented Jun 3, 2019 at 11:46
  • No, sorry iam not sure how to do that. Can you please elaborate. Commented Jun 3, 2019 at 12:35

2 Answers 2

1

Assets aren't magical, they need to be declared as such.

Open your angular.json file. Find the path

projects.YourProjectName.architect.build.options.assets

And from there, add your declared folder in it. It should keep the assets up when the project is complied.

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

Comments

0
  1. open your angular.json.
  2. add style in "styles": []
  3. add script in "scripts": []

reference link :- https://www.truecodex.com/course/angular-6/how-to-include-external-css-and-js-file-in-angular-6-angular-7

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.