2017-04-16 19 views
1

我想在我的angular2應用程序(primeng 2.0.5,Angular 2.0.x)中使用PrimgNG。我可以得到ButtonModule和InputTextModule的工作,但不是AutoCompleteModule。預渲染失敗,因爲錯誤:ReferenceError:事件沒有用PrimeNG AutoComplete定義

我在將AutoCompleteModule添加到應用程序後立即收到此錯誤。

An unhandled exception occurred while processing the request. 

Exception: Call to Node module failed with error: Prerendering failed because of error: ReferenceError: Event is not defined 

app.component.html:

<button pButton type="button" (click)="onclick()" >Click here</button> 
<p-autoComplete [(ngModel)]="text" [suggestions]="results" (completeMethod)="search($event)"></p-autoComplete> 

app.component.ts:

import { Component, OnInit } from '@angular/core'; 
import {ButtonModule, ToggleButtonModule} from 'primeng/primeng'; 

@Component({ 
    selector: 'app', 
    templateUrl: './app.component.html', 
    styleUrls: ['./app.component.css'], 
}) 

export class AppComponent { 
    text: string; 
    results: string[]; 
    search(event){ 
    this.results = ['1','2','3']; 
    } 

    onclick():void{ 
    alert("This is a test"); 
    } 
} 

app.module.ts:

import { NgModule } from '@angular/core'; 
import { RouterModule } from '@angular/router'; 
import { UniversalModule } from 'angular2-universal'; 
import { HttpModule } from '@angular/http'; 
import { FormsModule } from '@angular/forms'; 

import { AppComponent } from './components/app/app.component' 
import {ButtonModule, AutoCompleteModule} from 'primeng/primeng'; 

@NgModule({ 
    bootstrap: [AppComponent], 
    declarations: [ 
     AppComponent 
    ], 
    imports: [ 
     HttpModule, 
     FormsModule, 
     RouterModule.forRoot([ 
      { path: '', redirectTo: 'home', pathMatch: 'full' }, 
      { path: 'home', component: HomeComponent }, 
      { path: 'api-list', component: ApiListComponent }, 
      { path: 'api-add', component: ApiAddComponent }, 
      { path: '**', redirectTo: 'home', pathMatch: 'full' } 
     ]), 
     AutoCompleteModule, 
     UniversalModule 
    ] 
}) 
export class AppModule { 
} 

一切工作正常,如果我刪除了AutoCompleteModule。請幫忙。

回答

5

我能夠通過更改由ASP.Net核心模板生成的Index.cshtml頁面中的asp-prerender標記來解決此問題。我錯過了關於ASP.Net核心模板的觀點。

我變更後的標籤從

<app asp-prerender-module="ClientApp/dist/main-server">Loading...</app> 

<app asp-ng2-prerender-module="ClientApp/dist/main-server">Loading...</app> 
+0

我不認爲這是一個好的決定,工作速度慢很多 –

+0

@EvgenyBychkov由於性能影響而投了票?如果你知道解決這個問題的另一種方法,如果你能給我一個解決方案,我將不勝感激。 – user3731783

+0

看起來像primeng不支持服務器端渲染 –

2

剛剛起飛預渲染。

<app>Loading...</app> 

我發現這個答案在幾個星期前在這裏計算器,試圖再次尋找它,以它鏈接在這裏,但沒有取得任何結果。如果有人發現它,請在此鏈接。謝謝

0

以下

1..Loading .... 2.boot使用。 Browser.t s或boot.client.ts文件導入以下導入es6-shim

相關問題