2017-09-25 37 views
1

设置角2我是新来的角2,做配置我已经做了所有的要求,但仍然得到错误。 这是我的组件在Visual Studio

import { Component } from "@angular/core" 

@Component({ 

    selector = 'my-app', 
    template = `<h1> Hello {{name}} </h1>` 
}) 

export class AppComponent { 

    name: string = "First Project"; 
} 

我已经安装的node.js和快速启动文件在我的根文件夹已经和我已经从packages.json恢复包。但我有这个错误,当我建立我的项目

  • TS2552 - 找不到名称“选择”您的意思是选择
  • TS2304 - 无法找到名为“模板

这我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 { } 

这是我tsconfig.json

{ 
    "compileOnSave": true, 
    "compilerOptions": { 
    "target": "es5", 
    "module": "commonjs", 
    "moduleResolution": "node", 
    "sourceMap": true, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "lib": [ "es2015", "dom" ], 
    "noImplicitAny": true, 
    "suppressImplicitAnyIndexErrors": true, 
    "typeRoots": [ "../node_modules/@types" ] 
    } 
} 

回答

1

删除 '=',添加 ':',因为它是一个对象:

@Component({ 

    selector : 'my-app', 
    template : `<h1> Hello {{name}} </h1>` 
}) 
+1

谢谢:) #peace – faizan

+1

如果已完成,请接受答案:) –