Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript files not compiling on Angular 2 with Visual Studio 2015

I followed Zach's Answer and create new VS 2015 .NET 5 project and run Angular 2 with Typescript. It looks like its working. But there is a little problem:

MyApp.ts :

import { Component } from "angular2/core";

@Component({
    selector: "my-app",
    template: `
        <div>Hello from Angular 2</div>
    `
})
export class MyApp {
    public constructor() {
    }
}

When i change the template, type some different text, lets say <div>Some text here</div> , and then i recompile the project and run in browser to see the change - it still shows the older template text - Hello from Angular 2. So i checked in the MyApp.js (compiled from the MyApp.ts), and there is no change also.

(I tried building the project multiple times, also close VS and reopen it - MyApp.ts is compiled only once - the first time when its created.)

Additional files: (that may help solving)

tsconfig.json :

{
  "compilerOptions": {
    "target": "es5",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  },
  "exclude": [
    "node_modules"
  ]
}

Where it comes from (the problem)? Angular? Typescript? VS 2015? From my opinion - must be something with Typescript and its compilation? Any suggestions?

P.S: this implementation do not work on IE!

Progress: if i clean - rebuild - build my project - it compiles the .ts files, but its the same thing as the first time compilation - not actually a solution...

like image 276
Ceylan Mumun Kocabaş Avatar asked Dec 29 '25 08:12

Ceylan Mumun Kocabaş


1 Answers

I'm working in visual studio with a tsconfig file. For me, it works after add "compileOnSave" attribute, my tsconfig looks like this:

{
  "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
  }
}
like image 51
Luis Lopez Avatar answered Jan 01 '26 00:01

Luis Lopez