Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.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
Typescript System.import用法在我的控制台中导致多个错误_Typescript_Angular - Fatal编程技术网

Typescript System.import用法在我的控制台中导致多个错误

Typescript System.import用法在我的控制台中导致多个错误,typescript,angular,Typescript,Angular,我在我的组件中使用系统 export class LoginComponent { constructor() { System.import('app/login/login.js'); } } 文件加载很好,但TypeScript编译器说 错误:(10,9)TS2304:找不到名称“System”。 我的浏览器控制台说 EXCEPTION: Error: Uncaught (in promise): Error: Error: http://localhos

我在我的组件中使用
系统

export class LoginComponent {
    constructor() {
        System.import('app/login/login.js');
    }
}
文件加载很好,但TypeScript编译器说

错误:(10,9)TS2304:找不到名称“System”。

我的浏览器控制台说

EXCEPTION: Error: Uncaught (in promise): Error: Error: http://localhost:3000/app/login/login.js detected as register but didn't execute.
        at ZoneDelegate.invoke (http://localhost:3000/node_modules/angular2/bundles/angular2-polyfills.js:332:29)
        at Object.NgZoneImpl.inner.inner.fork.onInvoke (http://localhost:3000/node_modules/angular2/bundles/angular2.dev.js:2111:31)
        at ZoneDelegate.invoke (http://localhost:3000/node_modules/angular2/bundles/angular2-polyfills.js:331:35)
        at Zone.run (http://localhost:3000/node_modules/angular2/bundles/angular2-polyfills.js:227:44)
    Error loading http://localhost:3000/app/login/login.js

Error: Uncaught (in promise): Error: Error: http://localhost:3000/app/login/login.js detected as register but didn't execute.(…)
我该如何解决这个问题

如何使用ES6语法导入.js文件

两步:

  • vendor.d.ts

    声明模块“app/login/login”{ var foo:任何; 出口=食品; }

  • 在打字脚本中使用它

    从“app/login/login”导入*作为登录名

现在只需使用“--modulesystem”编译代码 如何使用ES6语法导入.js文件

两步:

  • vendor.d.ts

    声明模块“app/login/login”{ var foo:任何; 出口=食品; }

  • 在打字脚本中使用它

    从“app/login/login”导入*作为登录名


现在只需使用'--module system'编译代码,您就有一个错误,因为您没有SystemJS库的输入

大多数时候,我们不会在TypeScript文件中显式地使用
System.import
,因为我们可以让它在后台运行。我的意思是,当您使用以下内容时,TypeScript编译器会将导入转换为SystemJS支持的内容:

import {...} from 'app/login/login';

export class LoginComponent {
  constructor() {
  }
}
您可以注意到,我删除了
js
扩展,因为SystemJS允许在解析模块时配置要添加的默认扩展:

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

System.config({
包:{
应用程序:{
格式:'寄存器',
defaultExtension:'js'
}
}
});

您有一个错误,因为您没有SystemJS库的打字

大多数时候,我们不会在TypeScript文件中显式地使用
System.import
,因为我们可以让它在后台运行。我的意思是,当您使用以下内容时,TypeScript编译器会将导入转换为SystemJS支持的内容:

import {...} from 'app/login/login';

export class LoginComponent {
  constructor() {
  }
}
您可以注意到,我删除了
js
扩展,因为SystemJS允许在解析模块时配置要添加的默认扩展:

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

System.config({
包:{
应用程序:{
格式:'寄存器',
defaultExtension:'js'
}
}
});

为什么要在TypeScript中使用
System.import
而不是ES6导入语法?什么是
login.js
?在哪个文件中找到了
LoginComponent
?@rgvassar login.js是一个支持我的页面动画的脚本。如何使用ES6语法导入.js文件?为什么在TypeScript中使用
System.import
,而不是使用ES6导入语法?什么是
login.js
?在哪个文件中找到了
LoginComponent
?@rgvassar login.js是一个支持我的页面动画的脚本。如何使用ES6语法导入.js文件?我是TypeScript新手,因此我不清楚如何从'app/login/login'使用
import{…}导入
.js
文件。它只是说
找不到模块“app/login/login”。
我的目标是在加载模板后动态加载
.js
。System.import可以很好地处理此任务,但在控制台中会产生很多错误。您需要找到SystemJS(一个描述库的合同的
.d.ts
)文件的类型…我是TypeScript新手,所以我不清楚如何使用“app/login/login”中的
导入{…}来导入
.js
文件。它只是说
找不到模块“app/login/login”。
我的目标是在加载模板后动态加载
.js
。System.import可以很好地处理此任务,但会在控制台中引发许多错误。您需要查找描述库的合同的SystemJS(a
.d.ts
)文件的类型。。。