延迟加载后无任何输出显示

时间:2019-04-11 00:45:04

标签: angular

我为项目使用了延迟加载。之后,我无法获得系统的预期输出。控制台中没有任何错误。我在这段代码中看不到任何错误的内容。那我该怎么办。

我停止了终端,并通过npm start指令重新启动了项目。但什么也没发生。

app-routing.module.ts

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

const routes: Routes = [
  {
    path: 'invoice',
    loadChildren :'./invoice-builder/invoice-builder.module#InvoiceBuilderModule',

  },
  { 
    path: '',
    redirectTo: 'invoice',
    pathMatch: 'full'
  }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

invoice-builder-routing.module.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { InvoiceBuilderComponent } from './invoice-builder.component';

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

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class InvoiceBuilderRoutingModule { }

invoice-builder.module.ts

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

import { InvoiceBuilderRoutingModule } from './invoice-builder-routing.module';
import { InvoiceBuilderComponent } from './invoice-builder.component';

@NgModule({
  declarations: [InvoiceBuilderComponent],
  imports: [
    CommonModule,
    InvoiceBuilderRoutingModule
  ]
})
export class InvoiceBuilderModule { }

invoice-builder.component.ts

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

@Component({
  selector: 'app-invoice-builder',
  template: `
    <p>
      invoice-builder works!
    </p>
  `,
  styles: []
})
export class InvoiceBuilderComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}

预期输出为

invoice-builder works!

app.module.ts

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

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule} from '@angular/platform-browser/animations';
import { MaterialModule } from './shared/material.module';
import { InvoiceBuilderModule } from './invoice-builder/invoice-builder.module';


@NgModule({
  declarations: [
    AppComponent,

  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    BrowserAnimationsModule,
    MaterialModule,

  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

浏览器如下所示 enter image description here

“网络”选项卡显示如下 enter image description here

app.component.html

<router-outlet></router-outlet>

invoice-builder.component.ts

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

@Component({
  selector: 'app-invoice-builder',
  template: `
    <p>
      invoice-builder works!
    </p>
  `,
  styles: []
})
export class InvoiceBuilderComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}

enter image description here

1 个答案:

答案 0 :(得分:3)

您的代码对我来说看起来不错,我为您制作了一个堆炸弹。并且在app.component.html中,您还应该拥有List<Widget> _createButton(BuildContext context, List<Zone> zones) { return zones.map((Zone zone) { return RaisedButton( onPressed: () { setState(() { if (!zone.isSelected) { zone.color = AppColors.white; } }); }, color: zone.color ??= Theme.of(context).primaryColor, child: Text(zone.text), ); }).toList(); }

app.component.html

<router-outlet></router-outlet>

签出有效的堆栈炸弹here