10

In my index.html file i load angular 2 through cdn but it seems because i import the modules of angular 2 systemjs thinks that i must have them locally, how can i fix that?

<html>
<head>
    <base href="/">
    <title>Angular 2 Arc</title>
    <link rel="icon" type="image/x-icon" href="favicon.ico">
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>
  <ng2-app>Loading...</ng2-app>
  <!-- Load Angular 2 Core libraries -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.24/system.js"></script>
  <script src="https://npmcdn.com/rxjs@5.0.0-beta.2/bundles/Rx.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/2.0.0-beta.9/angular2-polyfills.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/2.0.0-beta.9/angular2.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/2.0.0-beta.9/http.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/2.0.0-beta.9/router.min.js"></script>
  <script src="https://npmcdn.com/angular2@2.0.0-beta.9/es6/dev/src/testing/shims_for_IE.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.35.0/es6-shim.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.20/system-polyfills.js"></script>
  <script src="https://code.angularjs.org/tools/system.js.map"></script>

  <!-- Load Bootstrap and Jquery -->
  <script src="lib/jquery/jquery.min.js" charset="utf-8"></script>
  <script src="lib/bootstrap/js/bootstrap.min.js" charset="utf-8"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-fork-ribbon-css/0.2.0/gh-fork-ribbon.min.css" />
  <link rel="stylesheet" href="/lib/bootstrap/css/bootstrap.min.css" media="screen" title="no title" charset="utf-8">
  <link rel="stylesheet" href="assets/css/app.css">
  <!-- Configure SystemJS -->
  <script>
      System.config({
          defaultJSExtensions: true,
          packages: {
              boot: {
                  format: 'register',
                  defaultExtension: 'js'
              }
          }
      });
      System.import('js/boot')
              .then(null, console.error.bind(console));
  </script>
</body>
</html>
zurfyx
  • 31,043
  • 20
  • 111
  • 145
Petros Kyriakou
  • 5,214
  • 4
  • 43
  • 82
  • What exact error do you have? – Thierry Templier Mar 18 '16 at 18:57
  • actually it required all files i used in my components but requires them locally. So its file not found 404 errors, for http.js, common.js, core etc – Petros Kyriakou Mar 18 '16 at 19:23
  • Also i noticed something weird. Can you go here and check the network using dev tools, it makes over 500 requests using system.src.js `https://angular2arc.herokuapp.com/` thus taking a lot of time to load. – Petros Kyriakou Mar 18 '16 at 19:24
  • Could you provide a plunkr? Thanks! – Thierry Templier Mar 18 '16 at 19:26
  • i have no idea how to upload my directory to plunker is that possible? can i give you a github repo instead? – Petros Kyriakou Mar 18 '16 at 19:31
  • Not sure. Here is a plunkr you can fork and update with your content: https://plnkr.co/edit/UKyRiq?p=info. – Thierry Templier Mar 18 '16 at 19:36
  • right now my index file is based on node modules folder and relying on a different configuration for system js.,i do not see how a plunkr can help, i mean i have gulp tasks, i have express server and the like, how can i replicate that on plunkr? ;o i know you are trying to help but plunkr in this case is not the way to go i think? i can only add the ts files but i think the problem could be in configuration or something? The reason i wanted to try cdn was to try to minimize loading time but. – Petros Kyriakou Mar 18 '16 at 19:45
  • You can refer to this on how angular team loads angular 2 from cdn: https://angular.io/resources/live-examples/quickstart/ts/plnkr.html – Randal Cunanan May 12 '16 at 16:32
  • Even worse is trying to find a Angular Material Design 2 cdn, ...not going to happen, it doesn't exist. Then when you post a bug they ask you to provide a plunker, lol. – Post Impatica Aug 27 '16 at 04:16

1 Answers1

2

With SystemJS you can provide a mapping to load module from a different location.

SystemJS.config({
  map: {
       '@angular': 'https://npmcdn.com/@angular'
   }
});

This will redirect all loading of a module @angular to that cdn location.

For more detailed info check systemjs.config.js in this plunker for more detailed info