我试图在我的应用程序中使用其他应用程序中的组件.我的项目在同一个文件夹中,所以我认为它会工作,但我得到“找不到模块”的例外.
有办法吗?或另一种方法来实现这一目标?
有办法吗?或另一种方法来实现这一目标?
到目前为止我所做的是:
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 */ ];
解决方法
您应该将要尝试使用的组件添加到您将要使用该组件的“功能”的父模块中.例如,假设此模块是您尝试使用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 ],bootstrap: [AppComponent] }) export class AppModule { }