微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Angular2 RC6升级

将我的项目更新为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内的支持删除.

所以,只需将您的指令移动到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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐