我正在尝试使用 PrimeNG 标签打开日历,但每次单击标签都不会打开日历,这是我的代码: 从 'primeng/calendar' 导入 {CalendarModule};
@NgModule({
declarations: [
AppComponent,
StoreMenuComponent
],
imports: [
BrowserModule,
AppRoutingModule,
ButtonModule,
InputTextModule,
FormsModule,
InputNumberModule,
CalendarModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
组件.ts
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
myDate1!: Date;
myEvent(evt: any)
{
console.warn(evt)
}
}
组件.html
</div>
<div class="field col-12 md:col-4">
<label for="icon">Icon</label>
<p-calendar [(ngModel)]="myDate1" [showIcon]="true" inputId="icon"></p-calendar>
</div>
其他工作的 primeNG 组件我都遇到了这个问题,谢谢谁能回答我
最后我通过添加解决:
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
在模块中
为了解决这个问题,我们应该使用provideAnimations()而不是BrowserAnimationsModule。
对于 Angular 版本 >= 17,这不是使用 Angular 动画的方法:
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
//...
],
//...
})
export class AppModule { }
来源:https://primeng.org/installation#animations
这是 Angular 版本 >= 17 使用 Angular 动画的方法
bootstrapApplication(AppComponent, {
providers: [
provideAnimationsAsync(),
]
});
来源:https://angular.dev/guide/animations#enabling-the-animations-module