如何使用CDN和SystemJS加载angular2 [英] How to load angular2 using CDN and SystemJS

查看:74
本文介绍了如何使用CDN和SystemJS加载angular2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的index.html文件中,我通过CDN加载了angular 2,但似乎是因为我导入了angular 2 systemjs模块,我认为我必须在本地安装它们,我该如何解决?

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>

推荐答案

使用SystemJS,您可以提供映射以从其他位置加载模块.

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

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

这会将模块@angular的所有加载重定向到该CDN位置.

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

有关详细信息,请在此 plunker 中查看systemjs.config.js

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

这篇关于如何使用CDN和SystemJS加载angular2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆