【问题标题】:No exported member 'PreLoadAllModules', in angular 2?角度 2 中没有导出的成员“PreLoadAllModules”?
【发布时间】:2017-06-27 01:17:51
【问题描述】:

我正在创建一个演示应用程序但出现此错误。我试图解决它但不能。请建议我做错了什么?我认为是 Angular 路由器包中的 PreloadAllModules 令牌。

错误的完整描述是:

app/app-routing.module.ts(33,15): error TS2305: Module '"/home/angular2/test/node_modules/@angular/router/index"' 没有导出成员 'PreLoadAllModules '。

代码如下:

import { RouterModule, Routes ,
         Router , ActivatedRoute,
         PreLoadAllModules         }    from '@angular/router'; 
import { NgModule                  }    from '@angular/core';
import { DashboardComponent        }    from './dashboard.component';
import { TestComponent             }    from './test.component';
import { ContactComponent          }    from './component/contact.component';
import { DirectiveExampleComponent }    from './component/directive.exp.component';
import { PowerBoosterComponent     }    from './component/power-booster.component';
import { PageNotFound              }    from './component/page.not.found.component';

export const routes: Routes = [
  { path:  'dashboard',                  component: DashboardComponent },
  { path:  'test',                       component: TestComponent },
  { path:  'contactus',                  component: ContactComponent },
  { path:  'directive',                  component: DirectiveExampleComponent },
  { path:  'pipeexamples',               component: PowerBoosterComponent,data:{name:'shubham',id:1} },
  { path:  '', redirectTo: '/dashboard', pathMatch: 'full' },
  { path:  '**',                         component: PageNotFound},

];

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

【问题讨论】:

    标签: angular typescript


    【解决方案1】:

    @angular/router/src/router_preloader.ts 这个类只存在于 Angular 2.1.x 或以上版本,请确保您使用的是最新的 Angular 版本。

    来源:

    https://github.com/angular/angular/blob/2.1.x/modules/@angular/router/src/router_preloader.ts#L44-L48

    【讨论】:

    • 我已经更新了我的 router_preloader.ts。但还是有同样的问题。
    【解决方案2】:

    我相信简单的拼写错误,正确的导入是:

    import { PreloadAllModules } from '@angular/router/router';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-24
      • 2019-09-08
      • 1970-01-01
      • 2019-12-05
      • 1970-01-01
      • 2019-10-07
      • 2018-12-22
      • 1970-01-01
      相关资源
      最近更新 更多