angulartypescripttypescript1.7

Angular2 TypeScript - error TS2307: Cannot find module 'angular2/core'


The version of my TypeScript 1.7.5

My main component file

// import {Component} from 'angular2/core';
import {Component, View} from 'angular2/core';
// import {bootstrap} from 'angular2/platform/browser';

    @Component({
        selector: 'my-app',
        // template: '<h1>My title: {{title}}</h1> <h2>Hardcoded h2</h2>'
    })
    @View({
        templateUrl: '/templates/home.html',
        directives: []
    })
    .Class({
        constructor: function() {

        }
    })

export class AppComponent {
    title = "My First Angular 2 App";
}

My HTML scripts

<!-- 1. Load libraries -->
<script src="node_modules/es6-shim/es6-shim.js"></script>
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>

<script src='app.component.js'></script>
<script src='app/boot.js'></script>

Next when I try to compile the file tsc app.component.ts --module system --experimentalDecorators

I get the following error: app.component.ts(2,31): error TS2307: Cannot find module 'angular2/core'.

Do you know what I'm missing here?


Solution

  • Remove:

    .Class({
        constructor: function() {
    
        }
    })
    

    Remove:

    @View({
        templateUrl: '/templates/home.html',
        directives: []
    })
    

    and put templateUrl: '/templates/home.html', in the @Component annotation instead.

    And apply the system.js configuration. In general follow the steps in here:

    https://angular.io/

    Check the second example.