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
Configuration Angular2的System.config-是否使用javascript或typescript?_Configuration_Angular - Fatal编程技术网

Configuration Angular2的System.config-是否使用javascript或typescript?

Configuration Angular2的System.config-是否使用javascript或typescript?,configuration,angular,Configuration,Angular,我刚刚开始设置Angular2应用程序,我不确定配置index.html的最佳方式是什么。我有两个例子:javascript版本和typescript版本。由于Angular2使用的是typescript,我认为typescript版本是有意义的。javascript版本来自Ari Lerner的新书Angular2。以下是两个示例: 类型脚本配置: System.config({ transpiler: 'typescript', typescriptOptions: {emi

我刚刚开始设置Angular2应用程序,我不确定配置index.html的最佳方式是什么。我有两个例子:javascript版本和typescript版本。由于Angular2使用的是typescript,我认为typescript版本是有意义的。javascript版本来自Ari Lerner的新书Angular2。以下是两个示例:

类型脚本配置:

System.config({
    transpiler: 'typescript',
    typescriptOptions: {emitDecoratorMetadata: true},
    packages: {app: {defaultExtension: 'ts'}}
});
System.import('app/app');
System.config({
  packages: {        
    app: {
      format: 'register',
      defaultExtension: 'js'
    }
  }
});
System.import('app/app.js')
    .then(null, console.error.bind(console));
Javascript配置:

System.config({
    transpiler: 'typescript',
    typescriptOptions: {emitDecoratorMetadata: true},
    packages: {app: {defaultExtension: 'ts'}}
});
System.import('app/app');
System.config({
  packages: {        
    app: {
      format: 'register',
      defaultExtension: 'js'
    }
  }
});
System.import('app/app.js')
    .then(null, console.error.bind(console));

我的问题是哪一个最适合使用,为什么?

Angular2应用程序可以使用打字脚本或ES5/ES6编写。在学习angular2时,你一定发现angular2网站提供了两种文档(实际上是三种),如果没有,现在就检查一下(你将能够看到Typescript的angular2、Javascript的angular2、Dart的angular2)

现在就看你要为哪个平台编写Angular2应用程序了

1)。如果您计划使用
typescript
编写angular2应用程序,显然您的目标web浏览器不会理解它,因此某些机制必须将typescript代码转换为目标web浏览器可以理解的
javascript
。因此,第一段代码意味着将/transfile
.ts
文件转换为
.js
,这样您的浏览器就可以理解了。


2)。如果您计划使用
Javascript/ES5/ES6
编写angular2应用程序,那么当然,问题的第二部分


建议:首先使用,因为Angular2本身从一开始就是用打字脚本编写的。

Angular2应用程序可以用打字脚本ES5/ES6编写。在学习angular2时,你一定发现angular2网站提供了两种文档(实际上是三种),如果没有,现在就检查一下(你将能够看到Typescript的angular2、Javascript的angular2、Dart的angular2)

现在就看你要为哪个平台编写Angular2应用程序了

1)。如果您计划使用
typescript
编写angular2应用程序,显然您的目标web浏览器不会理解它,因此某些机制必须将typescript代码转换为目标web浏览器可以理解的
javascript
。因此,第一段代码意味着将/transfile
.ts
文件转换为
.js
,这样您的浏览器就可以理解了。


2)。如果您计划使用
Javascript/ES5/ES6
编写angular2应用程序,那么当然,问题的第二部分


建议:使用first,因为Angular2本身是从头开始用typescript编写的。

首先,我认为JavaScript配置中有一个小错误:

System.config({
  packages: {        
    app: {
      format: 'register',
      defaultExtension: 'js'
    }
  }
});
System.import('app/app'); // <------
  .then(null, console.error.bind(console));
System.config({
包:{
应用程序:{
格式:'寄存器',
defaultExtension:'js'
}
}
});

System.import('app/app');// 首先,我认为JavaScript配置中有一个小错误:

System.config({
  packages: {        
    app: {
      format: 'register',
      defaultExtension: 'js'
    }
  }
});
System.import('app/app'); // <------
  .then(null, console.error.bind(console));
System.config({
包:{
应用程序:{
格式:'寄存器',
defaultExtension:'js'
}
}
});
System.import('app/app');//您可以查看我为开始使用
Typescript
而制作的种子应用程序,您可能会发现它很有帮助您可以查看我为开始使用
Typescript而制作的种子应用程序,您可能会发现它很有帮助