Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 系统配置defaultExtension不适用于Django_Javascript_Angularjs_Django_Angular_Systemjs - Fatal编程技术网

Javascript 系统配置defaultExtension不适用于Django

Javascript 系统配置defaultExtension不适用于Django,javascript,angularjs,django,angular,systemjs,Javascript,Angularjs,Django,Angular,Systemjs,我正在尝试用Django后端移植angular 2教程 这是我的html文件 <html> <head> <title>Angular 2 QuickStart</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="styles.css"&

我正在尝试用Django后端移植angular 2教程

这是我的html文件

<html>
  <head>
    <title>Angular 2 QuickStart</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">    
    <link rel="stylesheet" href="styles.css">

    <!-- 1. Load libraries -->
    <!-- IE required polyfills, in this exact order -->
    <script src="/static/main.js"></script>
    <script src="/static/node_modules/es6-shim/es6-shim.min.js"></script>
     <script src="/static/node_modules/systemjs/dist/system-polyfills.js"></script>
    <script src="/static/node_modules/angular2/es6/dev/src/testing/shims_for_IE.js"></script>   

    <script src="/static/node_modules/angular2/bundles/angular2-polyfills.js"></script>
    <script src="/static/node_modules/systemjs/dist/system.src.js"></script>
    <script src="/static/node_modules/rxjs/bundles/Rx.js"></script>
    <script src="/static/node_modules/angular2/bundles/angular2.dev.js"></script>

    <!-- 2. Configure SystemJS -->
    <script>
      System.config({
        packages: {        
          app: {
           format: 'register',
            defaultExtension: 'js'
           }
        }
      });
      System.import('/static/app/main')
            .then(null, console.error.bind(console));
    </script>
  </head>

 <!-- 3. Display the application -->
  <body>

    <my-app>Loading...</my-app>

  </body>
</html>
我必须使用

System.import('/static/app/main.js')
并将
.js
手动添加到所有我的非第三个库中,以便angular应用程序正常工作

有趣的是,我不必将
.js
添加到

'angular2/core'
'angular2/platform/browser'
因为System.js会自动解析导入,只要我为我编写的所有文件手动添加.js扩展名

但如果我设定

System.defaultJSExtensions = true;
我不必再将
.js
添加到我的文件中,但System.js失去了导入node_模块中所有库的功能,而是尝试使用默认的django目录

http://localhost:8000/myApp/angular2/platform/browser.js 
有人能给我一些指导吗


谢谢

我想您误解了
defaultJSExtensions
的配置。后者只允许在导入模块时添加
js
扩展:

System.defaultJSExtensions = true;

// requests ./some/module.js instead
System.import('./some/module');
如果之前未使用System.register显式注册模块,则此项适用

angular2.dev.js
文件包含用于angular2核心的模块(使用System.register显式注册)。包含带有
脚本
元素的文件只会使它们可用于导入

如果您想使用来自
node_modules/Angular2
(例如core.JS,…)的单个Angular2 JS文件,则需要以下SystemJS配置:

System.config({
  defaultJSExtensions: true,
  map: {
    angular2: 'node_modules/angular2/src',
    rxjs: 'node_modules/rxjs'
  },
  packages: {
    app: {
      defaultExtension: 'js',
      format: 'register'
    }
  }
});
System.import('app/boot')
  .then(null, console.error.bind(console));
上面重要的是
map
块,它告诉SystemJS在哪里可以找到名称以
angular2/
开头的模块


在这种情况下,无需导入Angular2捆绑的JS文件(Angular2.min.JS,…)

嗨,Kevin,你是如何解决这个问题的?我也被困在这个问题上了。
System.config({
  defaultJSExtensions: true,
  map: {
    angular2: 'node_modules/angular2/src',
    rxjs: 'node_modules/rxjs'
  },
  packages: {
    app: {
      defaultExtension: 'js',
      format: 'register'
    }
  }
});
System.import('app/boot')
  .then(null, console.error.bind(console));