简体   繁体   中英

System.import in angular 2 always try to import from url

Here is my html:

<script src="/static/angular-scripts/vendors/test/es6-shim.js" type="text/javascript"></script>
<script src="/static/angular-scripts/vendors/test/angular2-polyfills.js" type="text/javascript"></script>
<script src="/static/angular-scripts/vendors/test/system.src.js" type="text/javascript"></script>
<script src="/static/angular-scripts/vendors/test/Rx.js" type="text/javascript"></script>
<script src="/static/angular-scripts/vendors/test/angular2.dev.js" type="text/javascript"></script>

<script>
  System.config({
    packages: {        
      app: {
        format: 'register',
        defaultExtension: 'js'
     }
    }
   });
 System.import('angular/core')
        .then(null, console.error.bind(console));
</script>

The above code will output:

GET http://my_url/angular/core 500 (Internal Server Error)

How would you config SystemJS so that it doesn't find the path literally from the url, is there a way to config against it?

What are you doing with angular/core.it is API of anuglar2 that comes from the url that you added above. Normally we use System.import to import boot file. Heres the example,

<script src="https://code.angularjs.org/2.0.0-beta.1/angular2-polyfills.js"></script>
<script src="https://code.angularjs.org/tools/system.js"></script>
<script src="https://code.angularjs.org/tools/typescript.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.1/Rx.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.1/angular2.dev.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/2.0.0-beta.0/router.dev.js"></script>
 <script>
  System.config({
    transpiler: 'typescript', 
    typescriptOptions: { emitDecoratorMetadata: true }, 
    packages: {'app': {defaultExtension: 'ts'}} 
  });
  System.import('app/boot')
        .then(null, console.error.bind(console));
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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