Angular2错误TS1146:需要声明 [英] Angular2 error TS1146: Declaration expected
本文介绍了Angular2错误TS1146:需要声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Angular2新手在这里.
Angular2 Newbie here.
我正在使用Angular.io中的种子文件,但是当我运行"npm start"时,出现了tsc编译器错误-
I'm using the seed files from Angular.io but when I run 'npm start' I get a tsc compiler error -
tsc -p src/
tsc -p src/
src/app/app.module.ts(11,3):错误TS1146:需要声明.
src/app/app.module.ts(11,3): error TS1146: Declaration expected.
有人可以告诉我我想念的东西吗?我只有一个组件"AppComponent".
Can someone tell me what I'm missing please. I have only one component 'AppComponent'.
app.module.ts:
app.module.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 { }
app.component.ts
app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `
<h1>Hello</h1>
`,
})
export class AppComponent {
}
和index.html
and 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>
推荐答案
一切对我来说都很不错,除了在模板后面加了一个逗号...
Everything looks good to me except for maybe an extra comma after your template...
app.component.ts
app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `
<h1>Hello</h1>
`
})
export class AppComponent {
}
这篇关于Angular2错误TS1146:需要声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文