Angular2 RC7和angular

编程入门 行业动态 更新时间:2024-10-27 22:18:57
本文介绍了angular2 RC7和angular-cli Webpack中的延迟加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经使用ng new创建了一个新的应用程序,但是当我尝试配置模块以使用延迟加载进行加载时,我不断收到错误消息,找不到该模块.

I have created a new app using ng new but when I try to configure a module to load using lazy loading I keep getting an error that the module cannot be found.

EXCEPTION: Uncaught (in promise): Error: Cannot find module 'app/home/home.module'

package.json

"dependencies": { "@angular/common": "2.0.0-rc.7", "@angular/compiler": "2.0.0-rc.7", "@angular/core": "2.0.0-rc.7", "@angular/forms": "2.0.0-rc.7", "@angular/http": "2.0.0-rc.7", "@angular/platform-browser": "2.0.0-rc.7", "@angular/platform-browser-dynamic": "2.0.0-rc.7", "@angular/router": "3.0.0-rc.3", "core-js": "^2.4.1", "rxjs": "5.0.0-beta.12", "ts-helpers": "^1.1.1", "zone.js": "^0.6.21" }, "devDependencies": { "@types/jasmine": "^2.2.30", "angular-cli": "1.0.0-beta.11-webpack.9-4", "codelyzer": "~0.0.26", "jasmine-core": "2.4.1", "jasmine-spec-reporter": "2.5.0", "karma": "1.2.0", "karma-chrome-launcher": "^2.0.0", "karma-cli": "^1.0.1", "karma-jasmine": "^1.0.2", "karma-remap-istanbul": "^0.2.1", "protractor": "4.0.5", "ts-node": "1.2.1", "tslint": "3.13.0", "typescript": "2.0.2" }

  • angular2 RC7
  • angular-cli:1.0.0-beta.11-webpack.9-4
  • 节点:6.5.0
  • os:win32 x64
    • angular2 RC7
    • angular-cli: 1.0.0-beta.11-webpack.9-4
    • node: 6.5.0
    • os: win32 x64
    • import { ModuleWithProviders } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; const appRoutes: Routes = [{ path: '', redirectTo: 'home', pathMatch: 'full' }, { path: `home`, loadChildren: `app/home/home.module` }]; export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);

      app.module.ts

      import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { HttpModule } from '@angular/http'; import { AppComponent } from './appponent'; import { routing } from './app.routing'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, FormsModule, HttpModule, routing ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }

      appponent.ts

      import { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: 'appponent.html', styleUrls: ['appponent.css'] }) export class AppComponent { title = 'app works!'; }

      appponent.html

      <router-outlet></router-outlet>

      我确定我缺少一些愚蠢的东西,但是我尝试了各种选择,但到目前为止没有任何效果.有了我的配置,我会丢失任何东西吗?

      I'm sure I'm missing something stupid but I tried various options and nothing has worked so far. Given my configuration, am I missing anything?

      预先感谢, 斯蒂芬

      推荐答案

      使用RC7,您可以执行以下操作:

      With RC7, you can do as follow:

      const appRoutes: Routes = [ { path: 'home', loadChildren: 'app/home/home.module#HomeModule', } ];

      别忘了"#"

      然后终止服务并重新启动

      Then kill ng serve and restart it

      它将与angular-cli @ webpack一起使用

      It will works with angular-cli@webpack

      P.S:角度惯例是在延迟加载的文件夹前面加上(+),例如+ home/

      P.S: The angular convention is to prefix lazy loaded folders with a (+) e.g. +home/

更多推荐

Angular2 RC7和angular

本文发布于:2023-10-30 03:47:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1541666.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:angular

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!