将我的项目更新为RC6后发生以下错误:
Error: Typescript found the following errors: app.component.ts (12,3): Argument of type '{ moduleId: string; selector: string; templateUrl: string; styleUrls: string[]; directives: (type...' is not assignable to parameter of type 'ComponentMetadataType'. Object literal may only specify known properties,and 'directives' does not exist in type 'ComponentMetadataType'.
app.component.ts
import {Component,OnInit} from '@angular/core'; import {NavbarComponent} from "./shared/navbar/navbar.component"; import {ROUTER_DIRECTIVES} from "@angular/router"; import {SidebarComponent} from "./shared/sidebar/sidebar.component"; import {FooterComponent} from "./shared/footer/footer.component"; @Component({ moduleId: module.id,selector: 'app-root',templateUrl: 'app.component.html',styleUrls: ['app.component.css'],directives: [NavbarComponent,SidebarComponent,FooterComponent,ROUTER_DIRECTIVES] }) export class AppComponent implements OnInit { ngOnInit(): any { return undefined; } }
我需要一段时间,但我无法弄明白.
必须在@NgModule中定义指令和管道如果我正确读取. @Component内的支持被删除.
原文链接:https://www.f2er.com/angularjs/141894.html所以,只需将您的指令移动到NgModule中
目前你有:组件A的指令为Ac,组件B的指令为Bc,很可能是一个AppModule,你只需要将Ac和Bc移动到AppModule中.是的,你必须从@Component声明中删除它们
然后,指令将立即在模块中定义的组件中可用.
OP的示例变为:
app.component.ts
// imports... @Component({ selector: 'app-root',}) export class AppComponent {}
app.module.ts
// imports... @NgModule({ declarations: [ AppComponent,NavbarComponent,FooterComponent ],imports: [ BrowserModule,CommonModule,FormsModule ],providers: [ //MyService,MyOtherService ],entryComponents: [AppComponent],bootstrap: [AppComponent] }) export class AppModule {}
请参阅路由器的文档:router documentation