[英]Angular2 RC6 upgrade
after updating my project to RC6
following errors occurs: 将我的项目更新到
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 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;
}
}
It take my a while, but I cant figure it out. 我需要一段时间,但我无法弄明白。
Directives
and pipes
must be defined in @NgModule
If I'm reading correctly. 必须在
@NgModule
定义Directives
和pipes
如果我正确读取。 Support inside @Component
is removed. @Component
内部的支持被删除。
So yeah just move your directives into the NgModule 所以,只需将您的指令移动到NgModule中
At the moment you have : Component A with directives Ac and Component B with directives Bc and most likely one AppModule, you just have to move Ac and Bc into the AppModule. 目前你有:组件A带有指令Ac,组件B带有指令Bc,很可能是一个AppModule,你只需要将Ac和Bc移动到AppModule中。 And yes, you have to remove them from the
@Component
declaration 是的,你必须从
@Component
声明中删除它们
The directives will then be immediately available in the components that are defined in your module. 然后,指令将立即在模块中定义的组件中可用。
Example from OP becomes: OP的示例变为:
app.component.ts app.component.ts
// imports...
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
})
export class AppComponent {}
app.module.ts app.module.ts
// imports...
@NgModule({
declarations: [
AppComponent,
NavbarComponent,
SidebarComponent,
FooterComponent
],
imports: [
BrowserModule,
CommonModule,
FormsModule
],
providers: [
//MyService, MyOtherService
],
entryComponents: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule {}
See the doc for router : router documentation 请参阅doc for router : router文档
directives
and pipes
have to be defined in your @NgModule
declarations since RC6. 自RC6以来,必须在
@NgModule
声明中定义directives
和pipes
。 Remove them from your @Component
decorator. 从
@Component
装饰器中删除它们。
For Angular 2 final version 2.0.0.0 对于Angular 2最终版本2.0.0.0
the pipe should be declared in declaration section of app.module.ts file 管道应该在app.module.ts文件的声明部分声明
import {KeysPipe} from './keys.pipe';
@NgModule({
imports: [ BrowserModule, FormsModule, HttpModule ],
declarations: [ AppComponent, LoginComponent,ArticleComponent,**KeysPipe** ],
bootstrap: [ AppComponent, LoginComponent,ArticleComponent ],
})
just observe keyspipe implementation in above code snippets. 只需观察上面代码片段中的keyspipe实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.