Angular2 TypeScript - 错误 TS2307:找不到模块“angular2/core”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34747143/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 03:12:44  来源:igfitidea点击:

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

angulartypescripttypescript1.7

提问by Leon Gaban

The version of my TypeScript 1.7.5

我的 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

我的 HTML 脚本

<!-- 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

接下来当我尝试编译文件时 tsc app.component.ts --module system --experimentalDecorators

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

我收到以下错误:app.component.ts(2,31): error TS2307: Cannot find module 'angular2/core'.

Do you know what I'm missing here?

你知道我在这里缺少什么吗?

采纳答案by Langley

Remove:

消除:

.Class({
    constructor: function() {

    }
})

Remove:

消除:

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

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

templateUrl: '/templates/home.html',改为放入@Component 批注。

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

并应用system.js配置。一般按照这里的步骤操作:

https://angular.io/

https://angular.io/

Check the second example.

检查第二个例子。