0

I am working on an angular 4 project right now. I have my js files linked to in the index file that my app component gets rendered to.

<!DOCTYPE html>
<html>
  <head>
    <title>Angular QuickStart</title>
    <base href="/">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    
    <!-- Fonts -->
    <link rel="stylesheet" href="css/montserrat.css">
    <!-- CSS -->
    <!-- Bootstrap CSS
 ============================================ -->
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <!-- Icon Font CSS
 ============================================ -->
    <link rel="stylesheet" href="css/eleganticons.min.css">
    <!-- Plugins CSS
 ============================================ -->
    <link rel="stylesheet" href="css/plugins.css">
    <!-- Style CSS
 ============================================ -->
    <link rel="stylesheet" href="style.css">

    <!-- Polyfill(s) for older browsers -->
    <script src="node_modules/core-js/client/shim.min.js"></script>

    <script src="node_modules/zone.js/dist/zone.js"></script>
    <script src="node_modules/systemjs/dist/system.src.js"></script>

    <script src="systemjs.config.js"></script>
    <script>
      System.import('main.js').catch(function(err){ console.error(err); });
    </script>
  </head>

  <body>
    <my-app>
      <!--Preloader-->
      <div id="loading" class="preloader">
          <div class="loading-center">
              <div class="loading-center-absolute">
                  <div class="object object_one"></div>
                  <div class="object object_two"></div>
                  <div class="object object_three"></div>
                  <div class="object object_four"></div>
              </div>
          </div>
      </div>
    </my-app>
  </body>

  <!-- JS -->

<!-- jQuery JS
============================================ -->
<script src="js/vendor/jquery-1.12.0.min.js"></script>
<!-- Bootstrap JS
============================================ -->
<script src="js/bootstrap.min.js"></script>
<!-- Plugins JS
============================================ -->
<script src="js/plugins.js"></script>

<!-- Main JS
============================================ -->
<script src="js/main.js"></script>
</html>

When I load this page non of the javascript in those files are being executed, but when I put the component HTML code into the index file like above the js is executed and everything works. What do I need to do to make my js work. This is my first angular project so I am still trying to learn the in and outs of the framework.

John
  • 11
  • 1
  • 3

1 Answers1

0

Check out this Answer, might be helpful to you Load external js script dynamically in Angular 2 many other solutions are given there you can try.

Harry
  • 45
  • 2
  • 11