Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.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
如何使用Angular 2中的systemjs在组件中加载外部js文件?_Angular_Angular2 Routing - Fatal编程技术网

如何使用Angular 2中的systemjs在组件中加载外部js文件?

如何使用Angular 2中的systemjs在组件中加载外部js文件?,angular,angular2-routing,Angular,Angular2 Routing,我想在statComponent中加载test.js,我尝试在construncor中使用System.import,但我得到了以下错误:error:(SystemJS)XHR error(404未找到)加载 错误:XHR错误 import { Component, OnInit } from '@angular/core'; import { System } from 'systemjs'; @Component({ template: ` <div id="container"

我想在statComponent中加载test.js,我尝试在construncor中使用System.import,但我得到了以下错误:error:(SystemJS)XHR error(404未找到)加载 错误:XHR错误

 import { Component, OnInit } from '@angular/core';
import { System } from 'systemjs';

@Component({
template: `
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto">
 </div> 

`
})
export class StatComponent implements OnInit {
constructor() {
    System.import('./app/user/test.js').then(refToLoadedModule => {
        refToLoadedModule.someFunction();
    })
}

ngOnInit() { }
}

找不到js文件。检查你的路径。不,我认为system js“找不到名称'system”的问题是什么?URL是否存在,请在您的浏览器中尝试。否此问题:从“systemjs”导入{System},他无法加载它我用System.config.js更新qu我必须对此文件进行一些更改?您需要检查DevTools->Network。确切的404请求是什么?
  /**
 * System configuration for Angular 2 samples
 * Adjust as necessary for your application needs.
 */
 (function (global) {
 // map tells the System loader where to look for things
  var map = {
'app': 'dist', // 'dist',
'@angular': 'node_modules/@angular',
'rxjs': 'node_modules/rxjs',
'ng2-toasty': 'node_modules/ng2-toasty/bundles/index.umd.js'

  };
 // packages tells the System loader how to load when no filename and/or no 
extension
 var packages = {
'app': { main: 'main.js', defaultExtension: 'js' },
'rxjs': { defaultExtension: 'js' }
 };
 var ngPackageNames = [
'common',
'compiler',
'core',
'forms',
'http',
'platform-browser',
'platform-browser-dynamic',
 'router'
 ];
  // Individual files (~300 requests):
 function packIndex(pkgName) {
 packages['@angular/' + pkgName] = { main: 'index.js', defaultExtension: 
 'js' };
  }
  // Bundled (~40 requests):
 function packUmd(pkgName) {
packages['@angular/' + pkgName] = { main: '/bundles/' + pkgName + '.umd.js', 
defaultExtension: 'js' };
 }
 // Most environments should use UMD; some (Karma) need the individual index 
files
 var setPackageConfig = System.packageWithIndex ? packIndex : packUmd;
// Add package entries for angular packages
  ngPackageNames.forEach(setPackageConfig);
 var config = {
map: map,
packages: packages
 };
 System.config(config);
 })(this);