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
Angular2 TypeScript - error TS2307: Cannot find module 'angular2/core'
提问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.js
configuration.
In general follow the steps in here:
并应用system.js
配置。一般按照这里的步骤操作:
Check the second example.
检查第二个例子。