2017-04-16 14 views
1

私のangular2アプリケーション(primeng 2.0.5、Angular 2.0.x)でPrimgNGを使用しようとしています。 ButtonModuleとInputTextModuleは動作しますが、AutoCompleteModuleは動作しません。エラーのためプレレンダリングに失敗しました:ReferenceError:イベントがPrimeNGオートコンプリートで定義されていません

アプリケーションに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-ng2-prerender-module="ClientApp/dist/main-server">Loading...</app> 
+0

これは良い判断ではないと思いますが、動作が大幅に遅くなります –

+0

@EvgenyBychkovはパフォーマンスに影響を与えますか?あなたがこれを解決する別の方法を知っていれば、解決策を教えていただければ幸いです。 – user3731783

+0

primengはサーバー側のレンダリングをサポートしていないようです –

2

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

からタグを変更しました。

<app>Loading...</app> 

私はこの回答を数週間前にstackoverflowで見つけましたが、ここで再度リンクを検索しようとしましたが、結果は得られませんでした。もし誰かがそれを見つけたら、ここにリンクしてください。

1..Loading .... 2.boot以下のあなたが

0

利用いただきありがとうございます。 Browser.t sまたはboot.client.tsファイルは次のimport es6-shimをインポートします