RangeError:调用堆栈的最大大小超出了Angular 5 Router [英] RangeError: Maximum call stack size exceeded Angular 5 Router

查看:69
本文介绍了RangeError:调用堆栈的最大大小超出了Angular 5 Router的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我刚刚尝试在我的应用程序中设置模块的延迟加载,但是我在按照教程学习时遇到此错误,但是显然他们没有遇到相同的错误

Hey I've just tried to set up lazy loading of modules in my application but I'm getting this error I was following a tutorial but obviously they didnt get the same errors

我的设置如下

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { RouterModule, Routes, ActivatedRoute, ParamMap } from '@angular/router';
import { HttpClientModule } from '@angular/common/http';
import { environment } from '../environments/environment';
import { ServiceWorkerModule } from '@angular/service-worker';
import { OurWorkModule } from './our-work/our-work.module';
import { ourWorkRouting } from './our-work/our-work-routing.module';
import { AppComponent } from './app.component';
import { HomeComponent } from './home/home.component';
import { FooterComponent } from './shared/footer/footer.component';
import { WhatWeDoComponent } from './what-we-do/what-we-do.component';
import { HeaderComponent } from './shared/header/header.component';
import { OurProcessComponent } from './our-process/our-process.component';
import { OurTechnologyComponent } from './our-technology/our-technology.component';
import { GetInTouchComponent } from './get-in-touch/get-in-touch.component';

export const ROUTES: Routes = [
   { path: '', component: HomeComponent, pathMatch: 'full' },
   { path: 'what-we-do', component: WhatWeDoComponent},
   { path: 'our-work', loadChildren: 'app/our-work/our-work.module#OurWorkModule' },
   { path: 'our-technology', component: OurTechnologyComponent},
   { path: 'get-in-touch', component: GetInTouchComponent },
   { path: '**', redirectTo: ''}
];

@NgModule({
   declarations: [
      AppComponent,
      HomeComponent,
      FooterComponent,
      WhatWeDoComponent,
      HeaderComponent,
      OurProcessComponent,
      OurTechnologyComponent,
      GetInTouchComponent,
      HeaderHomeComponent,
   ],
  imports: [
     BrowserModule,
     LazyLoadImageModule,
     RouterModule.forRoot(ROUTES),
     FormsModule,
     HttpModule,
     HttpClientModule,
     ourWorkRouting,
     OurWorkModule,
     environment.production ? ServiceWorkerModule.register('/ngsw-worker.js') : [],
  ],
      providers: [EmailService],
      bootstrap: [AppComponent]
  })
  export class AppModule { }

我们的工作模块.ts

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule, Routes, ActivatedRoute, ParamMap } from '@angular/router';
import { OurWorkComponent } from './our-work.component';


@NgModule({
    imports: [
        CommonModule,
        RouterModule
    ],
    declarations: [
        OurWorkComponent,

    ]

})
export class OurWorkModule {}

our-work-routing.module.ts

import { Routes, RouterModule } from '@angular/router';
import { OurWorkComponent } from './our-work.component';

const ourWorkRoutes: Routes = [
    { path: '', component: OurWorkComponent }
];

export const ourWorkRouting = RouterModule.forChild(ourWorkRoutes);

这是我第一次尝试延迟加载模块或设置功能模块,以便于任何帮助!

this is the first time Ive tried to lazyload a module or set up a feature module so any help would be appreciated!

谢谢

推荐答案

这是我的延迟加载模块的外观,希望对您有帮助

Here's how my lazy loaded module looks, hope it helps you

import { NgModule, ApplicationRef, APP_BOOTSTRAP_LISTENER, NO_ERRORS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { APP_BASE_HREF, CommonModule } from '@angular/common';
import { Http, HttpModule } from "@angular/http";
import { RouterModule } from '@angular/router';
import { FormsModule } from '@angular/forms';

import { OurWorkComponent } from './our-work.component';

@NgModule({
    declarations: [
        OurWorkComponent
    ],
    imports: [
        CommonModule,
        FormsModule,
        HttpModule,
        RouterModule.forChild([
            { path: '', component: OurWorkComponent }
        ])
    ],
    providers : [
        //add services and other providers
    ],
    schemas: [ NO_ERRORS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA ]
})

export class FeaturedModule { }

我认为您没有在our-work-module.ts

这篇关于RangeError:调用堆栈的最大大小超出了Angular 5 Router的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆