为什么我在刚刚启动的Angular2应用程序中收到此错误?

ano*_*nym 2 angular

我刚刚开始编写一个我从中克隆的新的angular2应用程序 https://github.com/angular/quickstart

为什么我收到此错误?

app/app.component.ts(8,3):error TS2345:类型'{moduleId:string; selector:string; templateUrl:string; 指令:string []; }'不能分配给'Component'类型的参数.对象文字只能指定已知属性,"组件"类型中不存在"指令".

app.component.ts

import { Component } from '@angular/core';
import { NavbarComponent } from './components/navbar/navbar.component';

@Component({
  moduleId: module.id,
  selector: 'my-app',
  templateUrl: 'app.component.html',
  directives: [NavbarComponent]
})
export class AppComponent  {  }
Run Code Online (Sandbox Code Playgroud)

navbar-component.ts

import { Component } from '@angular/core';

@Component({
  moduleId: module.id,
  selector: 'navbar',
  templateUrl: `navbar.component.html`,
})
export class NavbarComponent  {  }
Run Code Online (Sandbox Code Playgroud)

San*_*ket 6

app.component.ts中删除以下行

directives: [NavbarComponent]
Run Code Online (Sandbox Code Playgroud)

并将其添加到app.module.ts中

@NgModule({
  imports:      [ BrowserModule ],
  declarations: [ AppComponent, NavbarComponent ], << add here
  bootstrap:    [ AppComponent ]
})
Run Code Online (Sandbox Code Playgroud)

2.0.0-rc.6中不再提供指令

  • 它已被弃用,已在rc.6中删除:https://github.com/angular/angular/commit/4a740f2 (2认同)