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

前端之家收集整理的这篇文章主要介绍了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 */
];

解决方法

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

猜你在找的Angularjs相关文章