【发布时间】:2017-03-03 01:20:01
【问题描述】:
我对 Angular2 还很陌生,我在将 Dragula 添加到我的应用程序时遇到了问题。当我运行应用程序时,会在加载主页之前引发错误:
Exception: Call to Node module failed with error: Prerendering failed because of error: ReferenceError: document is not defined
错误消息提到 Prerending,我怀疑这与使用 asp-prerender-module 的项目有关。
我尝试关注 Dragula 的官方教程和论坛帖子。下面是我的 app.module 和组件文件 sn-ps(... 表示汇总代码):
app.module.ts
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { UniversalModule } from 'angular2-universal';
import { AppComponent } from './components/app/app.component'
...
import { SearchComponent } from './components/search/search.component';
import { BrowserModule } from '@angular/platform-browser';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { Injectable } from '@angular/core';
import { DragulaModule } from 'ng2-dragula';
@NgModule({
bootstrap: [ AppComponent ],
declarations: [
AppComponent,
...
SearchComponent
],
imports: [
UniversalModule,
BrowserModule,
FormsModule,
DragulaModule,
CommonModule,
RouterModule.forRoot([
{ path: '', redirectTo: 'home', pathMatch: 'full' },
...
{ path: 'search', component: SearchComponent },
{ path: '**', redirectTo: 'home' }
])
]
})
export class AppModule {
}
search.component.ts
import { Component } from '@angular/core';
import { Http } from '@angular/http';
import { SearchService } from '../../services/search.service';
import { DragulaService } from 'ng2-dragula';
@Component({
selector: 'search',
template: require('./search.component.html'),
providers: [SearchService, DragulaService]
})
我怀疑在包含 Dragula 时我错过了一个步骤,但我不知道在哪里。我在 package.json 文件中包含了 dragula (^3.7.2) 和 ng2-dragula (^1.3.0)。
【问题讨论】:
-
您已经解决了这个问题吗?我对 ng2-dragula 模块有同样的问题。
-
我找到了解决这个问题的方法:stackoverflow.com/questions/40257514/…
标签: asp.net angular webpack dragula