2017-02-13 61 views
1

想象一個具有可重複使用的角度2組件的項目。現在在運行時,我將組件文件複製到另一個項目中,以便我能夠使用它們。應該怎麼做?Angular 2和systemjs:如何導入將在運行時創建的app.module.ts文件?

第一個問題是文件路徑無法被.ts識別,它並不真正存在,它將在運行時存在。

import { HelloComponent } from 'my-framework/components/hello/hello.component.ts'; 

此導入似乎工作,altouge .ts無法識別的URL,但在加載時,他找到該文件。現在,我在文件本身出現錯誤,這並不是我的理解。文件如何被編譯到項目中?

import { Component } from '@angular/core'; 

@Component({ 
    selector: 'hello', 
    template: `<h1>Hello {{name}}</h1>` 
}) 
export class HelloComponent { name = 'You'; } 

有人創建了一個項目的組件,並將它們插入到另一個項目,並能夠使用它們?我想我不明白它是如何完成的。

回答

0

在你app.module.ts文件,確保您在聲明組件:

`````

import { HelloComponent } from 'my-framework/components/hello/hello.component'; 
@NgModule({ 
    declarations: [ 
     MyApp, 
     HelloComponent 
    ] 

`````

相關問題