Angular2 新手。
我正在使用 Angular.io 中的种子文件,但是当我运行“npm start”时,出现 tsc 编译器错误 -
tsc -p src/
src/app/app.module.ts(11,3):错误 TS1146:需要声明。
有人可以告诉我我缺少什么吗?我只有一个组件“AppComponent”。
应用程序模块.ts:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
@NgModule({
imports: [ BrowserModule ],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
应用程序组件.ts
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `
<h1>Hello</h1>
`,
})
export class AppComponent {
}
和index.html
<!DOCTYPE html>
<html>
<head>
<title>Angular QuickStart</title>
<base href="/">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles.css">
<!-- Polyfill(s) for older browsers -->
<script src="node_modules/core-js/client/shim.min.js"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
<script>
System.import('main.js').catch(function(err){ console.error(err); });
</script>
</head>
<body>
<my-app>Loading AppComponent content here ...</my-app>
</body>
</html>
我今天遇到这个问题是因为我在 angualr 6 应用程序中犯了一个愚蠢的错误。我来自 C# 世界,我总是在每行后面使用分号 (;)。我在我的组件中做了同样的事情。
@Component({
selector: 'app-movies',
templateUrl: './movies.component.html',
styleUrls: ['./movies.component.css']
});
后来,这个post https://github.com/Microsoft/TypeScript/issues/21050驱使我解决这个问题,我需要删除@Component后面的分号(;)。
@Component({
selector: 'app-movies',
templateUrl: './movies.component.html',
styleUrls: ['./movies.component.css']
})
但我不确定为什么我们会在这种情况下收到此错误,我希望有人很快就能修复此问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)