.NETコアとWebpackでAngular 2を使用しています。私は自分のアプリケーションに動的にモジュールをロードしようとしています。ここではアプリケーションのコンポーネントは次のとおりです。 "this.loader.load(menu.modulePath)" 私はエラーを取得する時SystemJsNgModuleLoader "システムが定義されていません"
//our root app component
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import {
\t Component,
\t ViewContainerRef,
\t Compiler,
\t ComponentFactory,
\t ComponentFactoryResolver,
\t ModuleWithComponentFactories,
\t ComponentRef,
\t ReflectiveInjector,
\t SystemJsNgModuleLoader,
\t AfterViewInit,
\t OnInit,
\t NgModuleFactory
} from '@angular/core';
export class ModuleNode { modulePath: string; componentName: string; }
@Component({
selector: 'app',
template: require('./app.component.html'),
styles: [require('./app.component.css')]
})
export class AppComponent implements AfterViewInit {
\t widgetConfig: string;
\t module: ModuleNode;
\t cmpRef: ComponentRef<any>;
\t constructor(private viewref: ViewContainerRef,
\t \t private resolver: ComponentFactoryResolver,
\t \t private loader: SystemJsNgModuleLoader,
\t \t private compiler: Compiler) {
\t \t this.module = new ModuleNode();
\t \t this.module.modulePath = "./dynamic.module";
\t \t this.module.componentName = "TestComponent";
\t }
\t ngAfterViewInit() {
\t \t this.openWebApp(this.module);
\t }
\t ngOnInit() {
\t \t
\t }
\t openWebApp(menu: any) {
\t \t this.loader.load(menu.modulePath) // load the module and its components
\t \t \t .then((modFac) => {
\t \t \t \t this.compiler.compileModuleAndAllComponentsAsync<any>(modFac.moduleType)
\t \t \t \t \t .then((factory: ModuleWithComponentFactories<any>) => {
\t \t \t \t \t \t return factory.componentFactories.find(x => x.componentType.name === menu.componentName);
\t \t \t \t \t })
\t \t \t \t \t .then(cmpFactory => {
\t \t \t \t \t \t // need to instantiate the Module so we can use it as the provider for the new component
\t \t \t \t \t \t let modRef = modFac.create(this.viewref.parentInjector);
\t \t \t \t \t \t this.cmpRef = this.viewref.createComponent(cmpFactory, 0, modRef.injector);
\t \t \t \t \t \t // done, now Module and main Component are known to NG2
\t \t \t \t \t });
\t \t \t });
\t }
\t ngOnDestroy() {
\t \t if (this.cmpRef) {
\t \t \t this.cmpRef.destroy();
\t \t }
\t }
}
"システムが定義されていません"。 私が知っているように、それはSystemJsの一部である可能性がありますが、欠落している可能性があります.Net CoreとWebpackではもう必要ではありません。私は正しい?
あなたはどのバージョンのウェブパックを使用していますか? – yurzui
マイバージョン: webpack:1.12.14、webpack-externals-plugin:1.0.0、webpack-hot-middleware:2.10.0、webpack-merge:0.14.1、 – user3541236
webpack2が必要で、このスレッドを確認してくださいhttps: //github.com/angular/angular-cli/issues/2302 – yurzui