如何将第三方的文件导入Angular 2 Typescript项目?

时间:2017-02-13 08:30:20

标签: angularjs angular typescript

我有一个Angular 2项目,其中包含我们带来的组件到另一个用angular 1编写的项目。问题是文件就像第三方,我们不希望任何人提交它们只使用它们。文件进入“目标”文件夹,但在App.Module.ts我无法设置导入到该文件夹​​。知道如何正确地做到这一点吗?

我不知道的是,如果我们必须在'app.module.ts'文件中声明它以便在项目中使用它,我们如何使用在其他地方编写的componentnet。

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

import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';

/* HelloWorldComponent is a 3th party, its files are inside target folder,
so how to import it? */
/* import { HelloWorldComponent } from './app/hello-world.component';*/


@NgModule({
    declarations: [
        HelloWorldComponent
    ],
    imports: [
        BrowserModule,
        FormsModule,
        HttpModule,
        UpgradeModule
    ],
    exports: [
        HelloWorldComponent
    ],
    entryComponents: [
        HelloWorldComponent
    ],
    bootstrap: []
})

export class AppModule {
    ngDoBootstrap() {}
}


import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

platformBrowserDynamic().bootstrapModule(AppModule).then(platformRef => {
    const upgrade = platformRef.injector.get(UpgradeModule) as UpgradeModule;
    upgrade.bootstrap(document.body, ['myApp']);
    ;})


import * as _angular_ from 'angular';

declare global {
    const angular: typeof _angular_;
}

import { downgradeComponent } from '@angular/upgrade/static';

angular.module('myApp')
    .directive(
        'helloWorld',
        downgradeComponent({component: HelloWorldComponent}) as angular.IDirectiveFactory
    );

0 个答案:

没有答案