我刚开始编写一个全新的 angular2 应用程序,我从中克隆了它
https://github.com/angular/quickstart
为什么会出现此错误?
app/app.component.ts(8,3): error TS2345: Argument of type '{ moduleId: string; selector: string; templateUrl: string; directives: string[]; }' is not assignable to parameter of type 'Component'. Object literal may only specify known properties, and 'directives' does not exist in type '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 { }
navbar-component.ts
import { Component } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'navbar',
templateUrl: `navbar.component.html`,
})
export class NavbarComponent { }
最佳答案
从 app.component.ts
中删除以下行directives: [NavbarComponent]
并将其添加到app.module.ts
@NgModule({
imports: [ BrowserModule ],
declarations: [ AppComponent, NavbarComponent ], << add here
bootstrap: [ AppComponent ]
})
从 2.0.0-rc.6 开始不再提供指令
关于angular - 为什么我在刚启动的 Angular2 应用程序中会收到此错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41326611/