0

因此,在与版本进行了多次斗争之后,我有了一个全新的 angular-cli 启动应用程序,按照 Angular2-materials 自述文件完成了所有操作,获得了要加载和编译的按钮和卡片,并且我的应用程序仍然可以正常加载。

然后我在我的组件中添加了一个 Import for MdSidenavModule,一切都很好。然后在我的 app.module 文件的顶部调用 MdSidenavModule 的导入,并在 @NgModule 中将 MdSidenavModule 添加到导入部分,就像我为按钮和卡片所做的那样。除非我这样做并保存,否则我的应用程序可以正确编译,但它永远不会离开“正在加载...”并进入我应该打印“应用程序工作!”的组件。就像默认的 angular-cli 应用程序一样。

任何帮助将不胜感激!

我进入控制台的错误是

    zone.js:101 GET http://localhost:4200/vendor/@angular2-material/sidenav 404 (Not Found)scheduleTask @ zone.js:101ZoneDelegate.scheduleTask @ zone.js:336Zone.scheduleMacroTask @ zone.js:273(anonymous function) @ zone.js:122send @ VM1125:3fetchTextFromURL @ system.src.js:1154(anonymous function) @ system.src.js:1735ZoneAwarePromise @ zone.js:584(anonymous function) @ system.src.js:1734(anonymous function) @ system.src.js:2759(anonymous function) @ system.src.js:3333(anonymous function) @ system.src.js:3600(anonymous function) @ system.src.js:3985(anonymous function) @ system.src.js:4448(anonymous function) @ system.src.js:4700(anonymous function) @ system.src.js:406ZoneDelegate.invoke @ zone.js:323Zone.run @ zone.js:216(anonymous function) @ zone.js:571ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256drainMicroTaskQueue @ zone.js:474ZoneTask.invoke @ zone.js:426
zone.js:461 Unhandled Promise rejection: Error: XHR error (404 Not Found) loading http://localhost:4200/vendor/@angular2-material/sidenav
        at XMLHttpRequest.wrapFn [as _onreadystatechange] (http://localhost:4200/vendor/zone.js/dist/zone.js:769:30)
        at ZoneDelegate.invokeTask (http://localhost:4200/vendor/zone.js/dist/zone.js:356:38)
        at Zone.runTask (http://localhost:4200/vendor/zone.js/dist/zone.js:256:48)
        at XMLHttpRequest.ZoneTask.invoke (http://localhost:4200/vendor/zone.js/dist/zone.js:423:34)
    Error loading http://localhost:4200/vendor/@angular2-material/sidenav as "@angular2-material/sidenav" from http://localhost:4200/app/app.module.js ; Zone: <root> ; Task: Promise.then ; Value: Error: Error: XHR error (404 Not Found) loading http://localhost:4200/vendor/@angular2-material/sidenav(…)consoleError @ zone.js:461_loop_1 @ zone.js:490drainMicroTaskQueue @ zone.js:494ZoneTask.invoke @ zone.js:426
zone.js:463 Error: Uncaught (in promise): Error: Error: XHR error (404 Not Found) loading http://localhost:4200/vendor/@angular2-material/sidenav(…)

这是我的 app.module.ts

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { MdCardModule } from '@angular2-material/card';
import { MdButtonModule } from '@angular2-material/button';
import { MdSidenavModule } from '@angular2-material/sidenav';
import { AppComponent }  from './app.component';

@NgModule({
  imports:      [ BrowserModule, MdButtonModule, MdCardModule, MdSidenavModule],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

还有我的 app.component.ts

import { Component } from '@angular/core';
import { MdCardModule } from '@angular2-material/card';
import { MdButtonModule } from '@angular2-material/button';
import { MdSidenavModule } from '@angular2-material/sidenav';
@Component({
  moduleId: module.id,
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.css']
})
export class AppComponent {
  title = 'app works!';
}

我已经仔细检查并安装了sidenav,但为了确定,我也重新安装了它。不知道我错过了什么。

4

1 回答 1

0

我很笨,我忘了将它添加到要加载的 materialPkgs 数组中。

于 2016-08-28T05:05:09.623 回答