Skip to content

Commit 1e05c2e

Browse files
Merge pull request #20 from DHTMLX/next
Update Integration guides (new template)
2 parents 2310e6d + 070aba8 commit 1e05c2e

File tree

4 files changed

+372
-281
lines changed

4 files changed

+372
-281
lines changed

docs/guides/integration_with_angular.md

Lines changed: 98 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -24,93 +24,87 @@ Create a new **my-angular-event-calendar-app** project using Angular CLI. Run th
2424
ng new my-angular-event-calendar-app
2525
~~~
2626

27-
The command above installs all the necessary tools and dependencies, so you don't need to run any additional commands.
27+
The command above installs all the necessary tools, so you don't need to run any additional commands.
2828

2929
### Installation of dependencies
3030

31-
Go to the app directory:
31+
Go to the new created app directory:
3232

3333
~~~json
3434
cd my-angular-event-calendar-app
3535
~~~
3636

37-
Run the app with the following commands:
37+
Install dependencies and start the dev server. For this, use the [**yarn**](https://yarnpkg.com/) package manager:
3838

3939
~~~json
40-
yarn install
40+
yarn
4141
yarn start
4242
~~~
4343

4444
The app should run on a localhost (for instance `http://localhost:3000`).
4545

4646
## Creating Event Calendar
4747

48-
Now you should get the DHTMLX Event Calendar code. First of all, stop the app and proceed with installing the Event Calendar package.
48+
Now you should get the DHTMLX Event Calendar source code. First of all, stop the app and proceed with installing the Event Calendar package.
4949

5050
### Step 1. Package installation
5151

5252
Download the [**trial Event Calendar package**](/how_to_start/#installing-event-calendar-via-npm-and-yarn) and follow steps mentioned in the README file. Note that trial Event Calendar is available 30 days only.
5353

5454
### Step 2. Component creation
5555

56-
Now you need to create a component, to add an Event Calendar into the application. Create the **event-calendar** folder in the **src/app/** directory, add a new file into it and name it **event-calendar.component.ts**. Then complete the steps described below.
56+
Now you need to create an Angular component, to add Event Calendar into the application. Create the **event-calendar** folder in the **src/app/** directory, add a new file into it and name it **event-calendar.component.ts**. Then complete the steps described below.
5757

58-
#### Importing source files
58+
#### Import source files
5959

6060
Open the file and import Event Calendar source files. Note that:
6161

62-
- if you use PRO version and install the Event Calendar package from a local folder, the imported paths look like this:
62+
- if you use PRO version and install the Event Calendar package from a local folder, the imported path looks like this:
6363

6464
~~~jsx
6565
import { EventCalendar } from 'dhx-eventcalendar-package';
6666
~~~
6767

68-
- if you use the trial version of Event Calendar, specify the following paths:
68+
- if you use the trial version of Event Calendar, specify the following path:
6969

7070
~~~jsx
7171
import { EventCalendar } from '@dhx/trial-eventcalendar';
7272
~~~
7373

7474
In this tutorial you can see how to configure the **trial** version of Event Calendar.
7575

76-
#### Setting the container and adding Event Calendar
76+
#### Set the container and initialize Event Calendar
7777

78-
To display Event Calendar on the page, you need to set the container to render the component inside. Use the code below:
78+
To display Event Calendar on the page, you need to set the container to render the component inside and initialize Event Calendar using the corresponding constructor:
7979

80-
~~~jsx title="event-calendar.component.ts"
80+
~~~jsx {1,8,12-13,18-19} title="event-calendar.component.ts"
8181
import { EventCalendar } from '@dhx/trial-eventcalendar';
82-
import { Component, ElementRef, OnInit, ViewChild, OnDestroy} from '@angular/core';
82+
import { Component, ElementRef, OnInit, ViewChild, OnDestroy, ViewEncapsulation } from '@angular/core';
8383

8484
@Component({
85-
selector: 'event-calendar',
86-
template: '<div #container></div>'
85+
encapsulation: ViewEncapsulation.None,
86+
selector: "event-calendar", // a template name used in the "app.component.ts" file as <event-calendar />
87+
styleUrls: ["./event-calendar.component.css"], // include a css file
88+
template: `<div #container class="widget"></div>`,
8789
})
88-
export class EventCalendarComponent implements OnInit {
89-
@ViewChild('container', { static: true }) container!: ElementRef;
90-
}
91-
~~~
92-
93-
Then you need to render our Event Calendar in the container. To do that, use the `ngOnInit()` method of Angular:
9490

95-
~~~jsx {6-9} title="event-calendar.component.ts"
9691
export class EventCalendarComponent implements OnInit, OnDestroy {
97-
@ViewChild('container', { static: true }) container!: ElementRef;
92+
// initialize container for Event Calendar
93+
@ViewChild('container', { static: true }) calendar_container!: ElementRef;
9894

99-
private _calendar: any;
95+
private _calendar!: EventCalendar;
10096

10197
ngOnInit() {
102-
const calendar = new EventCalendar(this.container.nativeElement,{});
103-
this._calendar = calendar;
98+
// initialize the Event Calendar component
99+
this._calendar = new EventCalendar(this.calendar_container.nativeElement, {});
104100
}
105101

106-
ngOnDestroy() {
107-
this._calendar.destructor();
102+
ngOnDestroy(): void {
103+
this._calendar.destructor(); // destruct Event Calendar
108104
}
109105
}
110106
~~~
111107

112-
In the above code you also specified the `ngOnDestroy()` method that contains the `_calendar.destructor()` expression to clear the component when it is no longer needed.
113-
114108
#### Loading data
115109

116110
To add data into Event Calendar, you need to provide a data set. You can create the **data.ts** file in the **src/app/event-calendar/** directory and add some data into it:
@@ -148,69 +142,118 @@ export function getData() {
148142

149143
Then open the ***event-calendar.component.ts*** file. Import the file with data and specify the corresponding data properties to the configuration object of Event Calendar within the `ngOnInit()` method, as shown below.
150144

151-
~~~jsx {2,5,7} title="event-calendar.component.ts"
152-
// importing the data file
153-
import { getData } from './data';
145+
~~~jsx {2,18,20} title="event-calendar.component.ts"
146+
import { EventCalendar } from '@dhx/trial-eventcalendar';
147+
import { getData } from "./data"; // import data
148+
import { Component, ElementRef, OnInit, ViewChild, OnDestroy, ViewEncapsulation } from '@angular/core';
154149

155-
ngOnInit() {
156-
const events = getData();
157-
const calendar = new EventCalendar(this.container.nativeElement, {
158-
events
159-
});
150+
@Component({
151+
encapsulation: ViewEncapsulation.None,
152+
selector: "event-calendar",
153+
styleUrls: ["./event-calendar.component.css"],
154+
template: `<div #container class="widget"></div>`,
155+
})
156+
157+
export class EventCalendarComponent implements OnInit, OnDestroy {
158+
@ViewChild('container', { static: true }) calendar_container!: ElementRef;
159+
160+
private _calendar!: EventCalendar;
161+
162+
ngOnInit() {
163+
const events = getData(); // initialize data property
164+
this._calendar = new EventCalendar(this.calendar_container.nativeElement, {
165+
events, // apply event data
166+
date: new Date(2024, 5, 10),
167+
});
168+
}
169+
170+
ngOnDestroy(): void {
171+
this._calendar.destructor();
172+
}
160173
}
161174
~~~
162175

163-
You can also use the [`parse()`](/api/methods/js_eventcalendar_parse_method/) method inside the `ngOnInit()` method of Angular to load data into Event Calendar. It will reload data on each applied change.
176+
You can also use the [`parse()`](/api/methods/js_eventcalendar_parse_method/) method inside the `ngOnInit()` method of Angular to load data into Event Calendar.
164177

165-
~~~jsx {11} title="event-calendar.component.ts"
166-
// importing the data file
167-
import { getData } from './data';
178+
~~~jsx {2,18,23-24} title="event-calendar.component.ts"
179+
import { EventCalendar } from '@dhx/trial-eventcalendar';
180+
import { getData } from "./data"; // import data
181+
import { Component, ElementRef, OnInit, ViewChild, OnDestroy, ViewEncapsulation } from '@angular/core';
168182

169-
ngOnInit() {
170-
const events = getData();
171-
const calendar = new EventCalendar(this.container.nativeElement, {});
183+
@Component({
184+
encapsulation: ViewEncapsulation.None,
185+
selector: "event-calendar",
186+
styleUrls: ["./event-calendar.component.css"],
187+
template: `<div #container class="widget"></div>`,
188+
})
189+
190+
export class EventCalendarComponent implements OnInit, OnDestroy {
191+
@ViewChild('container', { static: true }) calendar_container!: ElementRef;
192+
193+
private _calendar!: EventCalendar;
194+
195+
ngOnInit() {
196+
const events = getData();
197+
this._calendar = new EventCalendar(this.calendar_container.nativeElement, {
198+
date: new Date(2024, 5, 10),
199+
});
200+
201+
// apply the data via the parse() method
202+
this._calendar.parse(events);
203+
}
172204

173-
calendar.parse(events);
205+
ngOnDestroy(): void {
206+
this._calendar.destructor();
207+
}
174208
}
175209
~~~
176210

177-
Now the Event Calendar component is ready. When the element will be added to the page, it will initialize the Event Calendar object with data. You can provide necessary configuration settings as well. Visit our [Event Calendar API docs](/api/overview/properties_overview/) to check the full list of available properties.
211+
The `parse(data)` method provides data reloading on each applied change.
212+
213+
Now the Event Calendar component is ready to use. When the element will be added to the page, it will initialize the Event Calendar with data. You can provide necessary configuration settings as well. Visit our [Event Calendar API docs](/api/overview/properties_overview/) to check the full list of available properties.
178214

179215
#### Handling events
180216

181217
When a user makes some action in the Event Calendar, it invokes an event. You can use these events to detect the action and run the desired code for it. See the [full list of events](/api/overview/events_overview/).
182218

183219
Open the **event-calendar.component.ts** file and complete the `ngOnInit()` method as in:
184220

185-
~~~jsx {4-6} title="event-calendar.component.ts"
221+
~~~jsx {7-9} title="event-calendar.component.ts"
222+
// ...
186223
ngOnInit() {
187-
const calendar = new EventCalendar(this.container.nativeElement,{ /*...*/ });
224+
this._calendar = new EventCalendar(this.calendar_container.nativeElement, {
225+
date: new Date(2024, 5, 10),
226+
});
188227

189-
calendar.events.on("add-event", (obj) => {
228+
this._calendar.events.on("add-event", (obj) => {
190229
console.log(obj);
191230
});
192231
}
232+
233+
ngOnDestroy(): void {
234+
this._calendar.destructor();
235+
}
193236
~~~
194237

195238
### Step 3. Adding Event Calendar into the app
196239

197-
Now it's time to add the component into your app. Open ***src/app/app.component.ts*** and use *EventCalendarComponent* instead of the default content by inserting the code below:
240+
To add the ***EventCalendarComponent*** component into the app, open the ***src/app/app.component.ts*** file and replace the default code with the following one:
198241

199-
~~~jsx title="app.component.ts"
242+
~~~jsx {5} title="app.component.ts"
200243
import { Component } from "@angular/core";
201244

202245
@Component({
203246
selector: "app-root",
204-
template: `<event-calendar/>`
247+
template: `<event-calendar/>` // a template created in the "event-calendar.component.ts" file
205248
})
206249
export class AppComponent {
207250
name = "";
208251
}
209252
~~~
210253

211-
Then create the ***app.module.ts*** file in the ***src/app/*** directory and insert the *EventCalendarComponent* as provided below:
254+
Then create the ***app.module.ts*** file in the ***src/app/*** directory and specify the *EventCalendarComponent* as shown below:
212255

213-
~~~jsx title="app.module.ts"
256+
~~~jsx {4-5,8} title="app.module.ts"
214257
import { NgModule } from "@angular/core";
215258
import { BrowserModule } from "@angular/platform-browser";
216259

0 commit comments

Comments
 (0)