使用 Visual Studio 2015 无法在 Angular 2 上编译 Typescript 文件

标签 typescript asp.net-mvc-5 visual-studio-2015 angular

我关注了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/

相关文章:

javascript - 通过值数组定义接口(interface)

javascript - TypeError : navigator. currentLang 不是函数

c# - 如何在 ASP.Net MVC 的 RedirectToAction 中传递临时数据

c# - MVC View 呈现为原始 HTML

Visual Studio 2015中的ReSharper大字体

c# - "Add Reference..."项目与共享项目之间的差异

reactjs - React hooks 被乱序调用

ASP.NET Core 1.0 - .NET 4.5 项目的 API 引用

wpf - 禁用 Visual Studio 2015 额外调试选项

typescript - vscode react native : launchReactNative. js