Angular2 - 使用第3个parety模块的组件

时间:2016-10-23 13:08:45

标签: angularjs angular

我创建了一个模块,其中有一个指令(ObDatePickerModule) 我还创建了一个项目,其中包含ObDatePickerModule个依赖项(在package.json中的依赖项下)。
接下来,我将在我的项目模块中导入模块A:

import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {ObDatePickerModule} from 'ng2-date-picker';

import {AppComponent} from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    ObDatePickerModule,
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {
}

这是项目的app.component:

import {Component} from '@angular/core';
import {ObDayPickerComponent} from 'ng2-date-picker';
import * as moment from 'moment';

@Component({
  selector: 'app-root',
  template: '<ob-day-picker [(ngModel)]="date"></ob-day-picker>',
  styleUrls: ['./app.component.css'],
  entryComponents: [ObDayPickerComponent]
})
export class AppComponent {
  date = moment();
}

以下是我收到的错误:

main.bundle.js:66421 Unhandled Promise rejection: Template parse errors:
'ob-day-picker' is not a known element:
1. If 'ob-day-picker' is an Angular component, then verify that it is part of this module.
2. If 'ob-day-picker' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message. ("[ERROR ->]<ob-day-picker [(ngModel)]="date"></ob-day-picker>

我检查了组件名称是否为ob-day-picker

我还安装了模块和ObDayPickerComponent导入的日志,似乎导入是正确的。

我错过了什么?

检查模块仓库:
https://bitbucket.org/vlio20/ng2-date-picker

该项目可在此处找到:
https://github.com/vlio20/3rd-ng2-module

1 个答案:

答案 0 :(得分:1)

如果您想在ObDayPickerComponent之外使用ObDatePickerModule,则必须将其导出为:

@NgModule({
  declarations: [
    AppComponent,
    ObDayPickerComponent,
    ObCalendarComponent
  ],
  imports: [
    BrowserModule,
    FormsModule
  ],
  exports: [ObDayPickerComponent], // this line
  bootstrap: [AppComponent]
})

export class ObDatePickerModule {}