1

Angular での遅延読み込みと混同しています。私は webpack2 と angular2 rc5 を使用しています。+lazyload コンポーネントに移動しようとすると失敗します

私の app.modules は次のようになります:

import { NgModule }       from '@angular/core';
import { BrowserModule }  from '@angular/platform-browser';
import { FormsModule }    from '@angular/forms';
import { AppComponent }       from './app.component';
import { SearchModule } from './search/search.module';
import {PagesModule} from "./pages/pages.module";

@NgModule({
imports: [
    BrowserModule,
    FormsModule,
    SearchModule,
    PagesModule,
    routing
],

declarations: [
    AppComponent
],
providers: [
    appRoutingProviders
],
bootstrap: [ AppComponent ]
})

export class AppModule {}

app.routing

import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router

import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

const appRoutes: Routes = [
{ path: '',  redirectTo: 'pages', pathMatch: 'full' }
];
export const appRoutingProviders: any[] = [];

export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);

ページ.モジュール

import { NgModule }      from '@angular/core';
import { CommonModule }  from '@angular/common';

import { routing }       from './pages.routing';


import { Pages } from './pages.component';

@NgModule({
  imports: [CommonModule, routing],
  declarations: [Pages]
})
export class PagesModule {}

ページ.ルーティング

import { Routes, RouterModule }  from '@angular/router';
import { Pages } from './pages.component';

const routes: Routes = [
  {
  path: 'pages',
  component: Pages,
  children: [
     { path: '', redirectTo: 'repositories', pathMatch: 'full' },
     { path: 'repositories', loadChildren: () =>  System.import('./repositories/repositories.module') }
  ];

 export const routing = RouterModule.forChild(routes);

repositories.module

import { NgModule }      from '@angular/core';
import { CommonModule }  from '@angular/common';
import { FormsModule } from '@angular/forms';

import { Repositories } from './repositories.component';
import { routing }       from './repositories.routing';

//module return exports component and it fail((((
import { SearchModule } from './search/search.module';

import {NavigationModule} from "./navigation/navigation.module";



@NgModule({
  imports: [
   CommonModule,
   FormsModule,
  NavigationModule,
  SearchModule,
  routing
 ],
 declarations: [
   Repositories
 ]
})
export default class RepositoriesModule {}

repositories.routing

 import { Routes, RouterModule }  from '@angular/router';
 import {Repositories} from "./repositories.component";


  const routes: Routes = [
    {
       path: '',
       component: Repositories,
       children: []
    }
  ];

export const routing = RouterModule.forChild(routes);

リポジトリ.コンポーネント

import {Component, ViewEncapsulation, Output} from '@angular/core';

@Component({
  selector: 'repositories',
  styles: [require('./repositories.scss')],
  template: `
         <div class="top-form">
            <search></search>
         </div>

         <div class="workspace">
            <navigation></navigation>
         </div>`
   })

  export class Repositories {
         constructor() {}

  }

search.module のような

import { NgModule }      from '@angular/core';
import { CommonModule }  from '@angular/common'; //без него не работает ngFor

import { Search } from './search.component';

//components
import { Aggregations } from './aggregations/aggregations.component';
import { AutoComplete } from './auto-complete/auto-complete.component';



 @NgModule({
   imports: [
   CommonModule
   ],

   declarations: [
      Aggregations,
       AutoComplete,
       Search
    ],
   exports: [ Search ]
 })

エクスポート クラス SearchModule {}

NavigationModule でルーティングを使用しようとしていますが、DOM から SearchModule を失います。どうしたの?

4

0 に答える 0