【发布时间】:2015-09-10 20:07:58
【问题描述】:
我正在关注在 Angular2 https://www.youtube.com/watch?t=10&v=ZsGRiHSaOxM 中构建路由的教程,它显示了使用 .ts 构建的部分页面,并且在每种情况下都有一个配套的 .js 文件。我的带有 atom-typescript 的 Atom 编辑器在我更改 app.ts 文件时将其编译为 app.js,但据我所知,我在另一个目录中的部分页面无法编译。
当文件是homePage.ts时,控制台错误是-找不到homePage.js 当文件是homePage.js时,控制台错误是-unexpected token @ on line(@Component在哪里)。我的 tsconfig 中有“compileOnSave”:true,并且该文件位于顶级项目目录中。
我尝试将fileGlob放入tsconfig,来自文档,如下
"filesGlob": [
"./**/*.ts",
"!./node_modules/**/*.ts"
],
没有任何改变。
我的编译器选项是:
"compilerOptions": {
"charset": " UTF-8",
"declaration": false,
"diagnostics": true,
"emitDecoratorMetadata": true,
"module": "commonjs",
"noImplicitAny": false,
"noLib": false,
"removeComments": true,
"sourceMap": true,
"target": "es5",
"version": true
},
我是否需要所有组件的 .ts 和 .js 文件,如果需要,如何使用 atom-typescript 实现这一点?或者为什么我会收到意外的令牌@错误?
【问题讨论】:
-
@的错误是跟踪器问题。你把它添加到你的项目中了吗?在你的视频中,这个人做到了。是的,你需要这两个文件:你用 typescript 编写,编译器将它转换成常规的 javascript(这是浏览器真正使用的)。 -
检查一下,这是一个使用 Angular 2 和 Typescript 启动和运行的最小项目,由 Angular 团队成员维护 -> github.com/pkozlowski-opensource/ng2-play.ts
-
埃里克,谢谢。是的,我在 index.html 页面中有其他脚本加载的 traceur,如下 -
-
jhadesdev,谢谢。那可能会奏效——科兹洛夫斯基知道他的东西。我的目标是了解有关构建 Angular2 的详细信息以及将 Atom 与 atom-typescript 一起使用,因为我有一种预感,所有这些都是未来的光明浪潮。
标签: typescript atom-editor angular