|
1 | | -# Sample15 |
| 1 | +# Integrating Syncfusion Angular Components with Angular and Electron Applications |
2 | 2 |
|
3 | | -This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 15.1.4. |
| 3 | +This document helps you to create a simple Angular application with `Electron Framework` and `Syncfusion Angular UI components`. |
4 | 4 |
|
5 | | -## Development server |
| 5 | +## Prerequisites |
6 | 6 |
|
7 | | -Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The application will automatically reload if you change any of the source files. |
| 7 | +Before getting started with the Angular project, make sure you have the following installed on your machine, |
8 | 8 |
|
9 | | -## Code scaffolding |
| 9 | +* [System requirements for Syncfusion Angular UI components](https://ej2.syncfusion.com/angular/documentation/system-requirement) |
| 10 | +* Electron CLI version - `^22.x.x` or later |
10 | 11 |
|
11 | | -Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. |
| 12 | +If you do not have the `Electron CLI` installed, refer to the [`Electron package`](https://www.npmjs.com/package/electron-cli) for instructions on how to install it. |
12 | 13 |
|
13 | | -## Build |
| 14 | +## Getting started with Syncfusion Angular component |
14 | 15 |
|
15 | | -Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. |
| 16 | +Follow the [documentation](https://ej2.syncfusion.com/angular/documentation/getting-started/angular-cli) to create an Angular application that includes Syncfusion Angular components. |
16 | 17 |
|
17 | | -## Running unit tests |
| 18 | +## Create main.js file |
18 | 19 |
|
19 | | -Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). |
| 20 | +Create a `main.js` file in the root folder of the project and update the below code, This file will serve as an entry-point for Electron and it is responsible for creating windows and handling all the system events that might occur in the app. |
20 | 21 |
|
21 | | -## Running end-to-end tests |
| 22 | +```typescript |
| 23 | +const { app, BrowserWindow } = require('electron'); |
| 24 | +let win; |
22 | 25 |
|
23 | | -Run `ng e2e` to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities. |
| 26 | +function createWindow() { |
| 27 | + win = new BrowserWindow({ width: 800, height: 600 }); |
24 | 28 |
|
25 | | -## Further help |
| 29 | + // Load the Angular app in the browser window |
| 30 | + win.loadFile('./dist/sample15/index.html'); |
26 | 31 |
|
27 | | -To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page. |
| 32 | + win.on('closed', () => { |
| 33 | + win = null; |
| 34 | + }); |
| 35 | +} |
| 36 | + |
| 37 | +app.on('ready', createWindow); |
| 38 | + |
| 39 | +app.on('window-all-closed', () => { |
| 40 | + if (process.platform !== 'darwin') { |
| 41 | + app.quit(); |
| 42 | + } |
| 43 | +}); |
| 44 | + |
| 45 | +app.on('activate', () => { |
| 46 | + if (win === null) { |
| 47 | + createWindow(); |
| 48 | + } |
| 49 | +}); |
| 50 | + |
| 51 | +``` |
| 52 | + |
| 53 | +## Update index.html |
| 54 | + |
| 55 | +In the `/src/index.html` file, change `<base href="/">` to `<base href="./">`, so that the Electron can able to find the Angular files. |
| 56 | + |
| 57 | +## Update package.json |
| 58 | + |
| 59 | +Go to your root directory and find the package.json file. Open its content and add the following, |
| 60 | + |
| 61 | +```typescript |
| 62 | +"main":"main.js", |
| 63 | +"scripts": { |
| 64 | + "ng": "ng", |
| 65 | + "start": "ng serve", |
| 66 | + "build": "ng build", |
| 67 | + "test": "ng test", |
| 68 | + "lint": "ng lint", |
| 69 | + "e2e": "ng e2e", |
| 70 | + "electron-build": "ng build --configuration=production", |
| 71 | + "electron": "electron ." |
| 72 | +}, |
| 73 | +``` |
| 74 | + |
| 75 | +## Running the application |
| 76 | + |
| 77 | +Finally, run the following command line to start the application. The Syncfusion Essential JS 2 menu component will be rendered in the Electron framework. |
| 78 | + |
| 79 | + ```bash |
| 80 | +npm run electron-build |
| 81 | + |
| 82 | +npm run electron |
| 83 | +``` |
0 commit comments