加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angular2 RC6升级

发布时间:2020-12-17 07:24:39 所属栏目:安全 来源:网络整理
导读:将我的项目更新为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 assig
将我的项目更新为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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读