繁体   English   中英

SystemJs,Angular2导入文件

[英]SystemJs, Angular2 importing files

这是我在index.html中的systemJs配置

<script>
  System.config({
    packages: {        
      app: {
        format: 'register',
        defaultExtension: 'js'
      }
    }
  });

  System.import('./ts/app.js')
        .then(null, console.error.bind(console));
</script>

app.js

import {Component} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser';

import {loginDirective} from './login-directive.js';

@Component({
selector: 'loginForm',
directives: [loginDirective],
templateUrl:'./view/login_view.html'
})

export class loginForm{

};

bootstrap(loginForm);

为什么我总是在import(login-directive.js)或系统js app.js中定义.js,而不仅仅是default-Extension设置为“ js”的login-directive和app?

tnx miha

实际上,对于您的SystemJS配置, format = 'register'defaultExtension = 'js'仅适用于以app /开头的模块。

System.import('app/boot')
    .then(null, console.error.bind(console));

或者是否位于component.js位于app文件夹下(我在这里认为导入是在app下的模块内完成的,例如app/boot模块):

import { ... } from './component';

这是结构:

app/
  boot.js (compiled from boot.ts)
  component.js (compiled from component.ts)

否则,SystemJS将尝试使用其名称直接加载模块

System.import('ts/app.js')
    .then(null, console.error.bind(console));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM