|
| 1 | +# Using the DevExtreme Angular 2 Integration with Ionic 2 |
| 2 | + |
| 3 | +## Create an Application |
| 4 | + |
| 5 | +Create an Ionic 2 application as described in the [Ionic 2 Tutorial](http://ionicframework.com/docs/v2/getting-started/tutorial/). |
| 6 | + |
| 7 | +## Install DevExtreme Angular 2 Integration |
| 8 | + |
| 9 | +Once the application is created, install DevExtreme Angular 2 integration npm package. Run the following command in the command prompt. |
| 10 | + |
| 11 | +``` |
| 12 | +npm install --save devextreme devextreme-angular |
| 13 | +``` |
| 14 | + |
| 15 | +## <a name="configuration"></a>Configure Ionic 2 for DevExtreme |
| 16 | + |
| 17 | +To use DevExtreme within the Ionic 2 application, import the required separate modules or entire DevExtreme to this application within the "src\app\app.module.ts" file. |
| 18 | + |
| 19 | +``` |
| 20 | +//Imports a separate module |
| 21 | +import { DxButtonModule } from 'devextreme-angular/ui/button'; |
| 22 | +
|
| 23 | +//Imports the entire DevExtreme |
| 24 | +import { DevExtremeModule } from 'devextreme-angular'; |
| 25 | +``` |
| 26 | + |
| 27 | +Add the imported modules to application imports: |
| 28 | + |
| 29 | +``` |
| 30 | +@NgModule({ |
| 31 | + ... |
| 32 | + imports: [ |
| 33 | + ... |
| 34 | + DevExtremeModule, |
| 35 | + ... |
| 36 | + ] |
| 37 | +}) |
| 38 | +``` |
| 39 | + |
| 40 | +## Copy DevExtreme Stylesheets |
| 41 | + |
| 42 | +DevExtreme style sheets are stored in the "node-modules\devextreme\dist\css" folder. You should copy them to the "www\assets\css" folder. You can do it manually, or use [ionic build tools](https://ionicframework.com/docs/v2/resources/app-scripts/) to copy style sheets during the build process. In the second case, copy the "copy.config.js" file from the [Ionic repository](https://github.com/driftyco/ionic-app-scripts/blob/master/config/copy.config.js) to the application root folder. |
| 43 | + |
| 44 | +Add the following item to the "copy" configuration. |
| 45 | + |
| 46 | +``` |
| 47 | +module.exports = { |
| 48 | + . . . |
| 49 | + copyStyleSheets: { |
| 50 | + src: ['{{ROOT}}/node_modules/devextreme/dist/css/**/*'], |
| 51 | + dest: '{{WWW}}/assets/css' |
| 52 | + } |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +Reference the created config within the package.json file by adding the "config" section. |
| 57 | + |
| 58 | +``` |
| 59 | +"config" : { |
| 60 | + "ionic_copy": "./copy.config.js" |
| 61 | +}, |
| 62 | +``` |
| 63 | + |
| 64 | +Add links to the required stylesheets to the head section of the "src\index.html" file. |
| 65 | + |
| 66 | +``` |
| 67 | +<link href="assets/css/dx.common.css" rel="stylesheet"> |
| 68 | +<link href="assets/css/dx.light.css" rel="stylesheet"> |
| 69 | +``` |
| 70 | + |
| 71 | +## Add a DevExtreme Component |
| 72 | + |
| 73 | +After you have performed all steps described above, you can use DevExtreme controls on application views. To try how it works, add a button widget to the "src\pages\hello-ionic\hello-ionic.html" file. |
| 74 | + |
| 75 | +``` |
| 76 | +. . . |
| 77 | +<ion-content padding> |
| 78 | + <h3>Welcome to your first Ionic app!</h3> |
| 79 | + <dx-button text="Hello world"></dx-button> |
| 80 | +. . . |
| 81 | +``` |
| 82 | + |
| 83 | +For more information on working with DevExtreme controls in Angular 2 approach, refer to the [DevExtreme-Angular library description](https://github.com/DevExpress/devextreme-angular). |
| 84 | + |
| 85 | +## Run the Application |
| 86 | + |
| 87 | +Run the app using the following command |
| 88 | + |
| 89 | +``` |
| 90 | +ionic serve |
| 91 | +``` |
0 commit comments