由于以下原因,预渲染失败:ReferenceError:未使用PrimeNG AutoComplete定义事件 [英] Prerendering failed because of error: ReferenceError: Event is not defined with PrimeNG AutoComplete
问题描述
我正在尝试在我的angular2应用程序(primeng 2.0.5,Angular 2.0.x)中使用PrimgNG.我可以使用ButtonModule和InputTextModule,但不能使用AutoCompleteModule.
I am trying to use PrimgNG in my angular2 app (primeng 2.0.5, Angular 2.0.x). I can get the ButtonModule and InputTextModule work but not the AutoCompleteModule.
将AutoCompleteModule添加到应用程序后,我会收到此错误.
I am getting this error as soon as I add AutoCompleteModule to the application.
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:
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:
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:
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,一切正常.请帮忙.
Everything works fine if I remove AutoCompleteModule. Please help.
推荐答案
我能够通过更改ASP.Net Core模板生成的Index.cshtml页面中的asp-prerender标签来解决此问题.来自我的问题的ASP.Net Core模板.
I was able to solve this by changing the asp-prerender tag in Index.cshtml page that is generated by ASP.Net Core Templates.I missed the point about ASP.Net Core templates from my question.
我从
<app asp-prerender-module="ClientApp/dist/main-server">Loading...</app>
到
<app asp-ng2-prerender-module="ClientApp/dist/main-server">Loading...</app>
这篇关于由于以下原因,预渲染失败:ReferenceError:未使用PrimeNG AutoComplete定义事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!