gpt4 book ai didi

angular - 由于错误 : ReferenceError: Event is not defined with PrimeNG AutoComplete,预呈现失败

转载 作者:太空狗 更新时间:2023-10-29 19:36:40 26 4
gpt4 key购买 nike

我正在尝试在我的 angular2 应用程序(primeng 2.0.5、Angular 2.0.x)中使用 PrimgNG。我可以让 ButtonModule 和 InputTextModule 工作,但不能让 AutoCompleteModule 工作。

我将 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

应用程序组件.html:

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

应用程序组件.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");
}
}

应用程序模块.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,一切正常。请帮忙。

最佳答案

我能够通过更改由 ASP.Net Core 模板生成的 Index.cshtml 页面中的 asp-prerender 标签来解决这个问题。我错过了我的问题中有关 ASP.Net Core 模板的要点。

我把标签改成了

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

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

关于angular - 由于错误 : ReferenceError: Event is not defined with PrimeNG AutoComplete,预呈现失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43442770/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com