在角度2(RC5)中使用多个自定义模块

前端之家收集整理的这篇文章主要介绍了在角度2(RC5)中使用多个自定义模块前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经将不断增长的ng2应用程序升级到RC5,并将所有组件/管道摆放到一个胖主模块中.为了对抗这个膨胀,我试图将我的应用程序刻录到单独的模块中(同样也是为了最终做延迟加载).

我创建了一个包含一些通用组件的子模块:

我-shared.module.ts

import { NgModule }      from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { FormsModule } from "@angular/forms";
import { provideForms,disableDeprecatedForms } from"@angular/forms";

import { TabBarWidgetComponent } from "./tabBarWidget/tabbar-widget.component";
import { MyDatepickerComponent } from "./mykDatePicker/my-datepicker.component";
import { CalendarSelectorComponent } from "./calendarSelector/calendar-selector.component";
import { AccordionTabComponent } from "./accordionTab/accordion-tab.component";


@NgModule({
  imports: [
      BrowserModule,FormsModule
  ],declarations: [
      TabBarWidgetComponent,MyDatepickerComponent,CalendarSelectorComponent,AccordionTabComponent

  ],providers: [
      provideForms(),disableDeprecatedForms()
  ]

})
export class MySharedModule { }

到现在为止还挺好.现在我想在主app.module.ts中引用这个MySharedModule,我正在做这样的事情:

import { NgModule }      from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { FormsModule } from "@angular/forms";
import { HttpModule } from "@angular/http";

import { MySharedModule } from "./shared/my-shared.module";

import { Some1Component } from "./folder/some1.component";
import { Some2Component } from "./folder/some2.component";
import { Some3Component } from "./folder/some3.component";
import { Some4Component } from "./folder/some4.component";
import { Some5Component } from "./folder/some5.component";

import "rxjs/add/operator/map";
import "rxjs/add/operator/toPromise";

@NgModule({
  imports: [
    BrowserModule,FormsModule,HttpModule,MySharedModule
  ],declarations: [
    AppComponent,Some1Component,Some2Component,Some3Component,Some4Component,Some5Component,],providers: [],bootstrap: [AppComponent],entryComponents: []

})
export class AppModule { }

问题是我收到以下错误(这表明子模块组件未被app.module.ts中定义的应用程序识别):

Can’t bind to ‘tabs’ since it isn’t a known property of ‘tab-bar’.
1. If ‘tab-bar’ is an Angular component and it has ‘tabs’ input,then verify that it is part of this module.
2. If ‘tab-bar’ is a Web Component then add “CUSTOM_ELEMENTS_SCHEMA” to the ‘@NgModule.schema’ of this component to suppress this message.

谁能看到我做错了什么?

尝试在共享模块中添加导出部分.
import { NgModule }      from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { FormsModule } from "@angular/forms";
import { provideForms,exports: [
      TabBarWidgetComponent,AccordionTabComponent
  ],disableDeprecatedForms()
  ]

})
export class MySharedModule { }
原文链接:https://www.f2er.com/angularjs/140602.html

猜你在找的Angularjs相关文章