You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular项目使用EJS-Schedule报错:Cannot read property 'trim' of undefined

Fixing "Cannot read property 'trim' of undefined" in EJ2 Schedule Component for Angular

That error pops up because the Schedule component isn’t getting the necessary setup to properly format date ranges when rendering the week view. Let’s walk through the fixes step by step:

1. Register all required view services

The EJ2 Schedule relies on specific services to render different views (day, week, month, etc.). Even if you’re just using the default week view, you need to provide these services in your module to avoid initialization gaps.

Update your app.module.ts to include the required services:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ScheduleModule, DayService, WeekService, WorkWeekService, MonthService, AgendaService } from '@syncfusion/ej2-angular-schedule';
import { AppComponent } from './app.component';

@NgModule({
  imports: [BrowserModule, ScheduleModule],
  declarations: [AppComponent],
  // Add these core view services to the providers array
  providers: [DayService, WeekService, WorkWeekService, MonthService, AgendaService],
  bootstrap: [AppComponent]
})
export class AppModule { }

2. Set an initial currentDate for the component

Without a defined starting date, the component struggles to compute the date range for the header, leading to that undefined value that triggers the trim error.

Update your component’s TS file:

import { Component, ViewChild } from '@angular/core';
import { ScheduleComponent } from '@syncfusion/ej2-angular-schedule';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  @ViewChild('scheduleObj', {static: true}) public schedule: ScheduleComponent;
  // Define an initial current date to anchor the schedule
  public currentDate: Date = new Date();
}

Then bind this property in your HTML template:

<ejs-schedule #scheduleObj [currentDate]="currentDate"></ejs-schedule>

3. Verify version compatibility

Double-check that your @syncfusion/ej2-angular-schedule version matches your Angular version. Mismatched versions can cause unexpected initialization bugs. You can cross-reference compatible versions in Syncfusion’s official version matrix.

After applying these steps, the component should initialize properly without the "trim of undefined" error.

内容的提问来源于stack exchange,提问作者medi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 13:02:30