2016-07-14 49 views
4

我尝试从其他应用程序在我的应用程序中使用组件。我的项目是在同一个文件夹,所以我认为它会工作,但我得到“无法找到模块”异常。 有没有办法做到这一点?或另一种方式来实现这一目标?Angular2-使用另一个应用程序中的组件

我做了什么至今:

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 */ 
]; 

回答

0

您应该添加您要使用到“功能”,其中的父模块组件您将使用该组件。例如,假设此模块是您尝试使用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 { } 
相关问题