TypeScript - 错误 TS1146:需要声明
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34735530/
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
TypeScript - error TS1146: Declaration expected
提问by Leon Gaban
I got the latest TypeScriptvia npm (npm install -g typescript
)
我通过 npm ( )获得了最新的TypeScriptnpm install -g typescript
Version 1.7.5
Version 1.7.5
When I run the typescript compile command on my file: tsc app.component.ts --module system
当我在我的文件上运行 typescript compile 命令时: tsc app.component.ts --module system
I get the following error: app.component.ts(15,7): error TS1146: Declaration expected.
我收到以下错误: app.component.ts(15,7): error TS1146: Declaration expected.
import {Component} from 'angular2/core';
@Component({
selector: 'my-app',
// template: '<h1>My title: {{title}}</h1> <h2>Hardcoded h2</h2>'
})
@View({ // <- line 7
templateUrl: '/templates/home.html',
directives: []
})
.Class({
constructor: function() {
}
}); // <- line 15
export class AppComponent {
title = "My First Angular 2 App";
}
Anyone know what this error means?
有谁知道这个错误是什么意思?
采纳答案by kennypu
you need to import View
from angular2/core
as well:
你需要进口View
从angular2/core
,以及:
import {Component, View} from 'angular2/core';
import {Component, View} from 'angular2/core';
回答by luhuang
Try this
试试这个
import { Component } from '@angular/core';