Angular2-使用来自其他应用程序的组件

时间:2016-07-14 11:30:01

标签: angular

我正试图在我的应用中使用其他应用中的组件。我的项目在同一个文件夹中,所以我认为它可以工作,但我得到了#34;找不到模块"例外。 有办法吗?或另一种方法来实现这一目标?

到目前为止我所做的是:

import { Component, OnInit } from '@angular/core';
import { OverviewPaginationComponent } from './../../../../overview/src/app/overview-pagination/overview-pagination.component.ts';

@Component({
  moduleId: module.id,
  selector: 'combi',
  template: `
 <overview-pagination><overview-pagination>

`,
  styleUrls: ['combi.component.css'],
  providers: [],
  directives: [OverviewPaginationComponent]
})
export class CombiComponent implements OnInit {

  constructor() {}

  ngOnInit() {
  }

}

并在systemConfig中定义:

const barrels: string[] = [
  // Angular specific barrels.
  '@angular/core',
  '@angular/common',
  '@angular/compiler',
  '@angular/forms',
  '@angular/http',
  '@angular/router',
  '@angular/platform-browser',
  '@angular/platform-browser-dynamic',
  '@angular/router-deprecated',

  // Thirdparty barrels.
  'rxjs',

  // App specific barrels.
  'app',
  'app/shared',
  'app/combi',
  '../../overview/src/app/overview-pagination',
  /** @cli-barrel */
];

1 个答案:

答案 0 :(得分:0)

您应该将您尝试使用的组件添加到该功能的主要模块&#39;您将在哪里使用该组件。例如,假设此模块是您尝试使用OverviewPaginationComponent的父模块:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { OverviewPaginationComponent } from 'path';


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