0
我對Angular2相當新,並且遇到了將Dragula添加到我的應用程序的問題。當我運行應用程序錯誤加載主頁之前拋出:將Dragular添加到Angular2應用程序:文檔未定義
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和組件文件片段(...表示彙總碼):
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模塊有同樣的問題。 –
我發現此問題的修復程序:http://stackoverflow.com/questions/40257514/call-to-node-module-failed-with-errors-with-angular2-asp-net –