我关注了Zach's Answer并创建新的 VS 2015 .NET 5 项目并使用 Typescript 运行 Angular 2。它看起来像它的工作。但是有个小问题:
MyApp.ts:
import { Component } from "angular2/core";
@Component({
selector: "my-app",
template: `
<div>Hello from Angular 2</div>
`
})
export class MyApp {
public constructor() {
}
}
当我更改模板时,键入一些不同的文本,比如说 <div>Some text here</div>
,然后我重新编译项目并在浏览器中运行以查看更改 - 它仍然显示旧模板文本 - Hello from Angular 2。所以我检查了 MyApp.js
(编译自 MyApp.ts
),也没有变化。
(我尝试多次构建项目,也关闭 VS 并重新打开它 - MyApp.ts
仅编译一次 - 第一次创建时。)
其他文件:(可能有助于解决)
tsconfig.json :
{
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules"
]
}
它来自哪里(问题)? Angular ? typescript ?与 2015 年相比? 在我看来 - 一定是 Typescript 及其编译的东西吗?有什么建议么?
P.S:此实现不适用于 IE!
进度: 如果我清理 - 重建 - 构建我的项目 - 它编译 .ts 文件,但它与第一次编译相同 - 实际上不是解决方案...
最佳答案
我在 visual studio 中使用 tsconfig 文件工作。对我来说,它在添加“compileOnSave”属性后起作用,我的 tsconfig 如下所示:
{
"compileOnSave": true, <---- Added this line
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [ "es2015", "dom" ],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
}
}
关于使用 Visual Studio 2015 无法在 Angular 2 上编译 Typescript 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36791432/