将我的项目更新为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;
}
}
我花了一段时间,但我无法弄清楚。
Directives
并且pipes
必须在“@NgModule
我阅读正确”中定义。内部支撑@Component
被移除。
所以是的,只需将您的指令移至NgModule中
现在,您有了:带有指令Ac的组件A和带有指令Bc的组件B,最有可能是一个AppModule,只需要将Ac和Bc移到AppModule中即可。是的,您必须将它们从@Component
声明中删除
这些指令将立即在模块中定义的组件中可用。
OP中的示例变为:
app.component.ts
// imports...
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
})
export class AppComponent {}
app.module.ts
// imports...
@NgModule({
declarations: [
AppComponent,
NavbarComponent,
SidebarComponent,
FooterComponent
],
imports: [
BrowserModule,
CommonModule,
FormsModule
],
providers: [
//MyService, MyOtherService
],
entryComponents: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule {}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句