You can compile the app in the browser, at runtime, as the application loads, using the Just-in-Time (JiT) compiler as we did until now. But there is another way called "AHEAD-OF-TIME" COMPILATION which as said in Angular2 official site: "radically improves performance". Here we convert the components and templates to executable JavaScript files before runtime.
Steps:
The root folder contains our index.html
, a few configuration files, and the app
folder which holds the main content of the application.
/root
/app
/app.component.ts
/app.module.ts
/main.ts
/other source files
/index.html
/package.json
/tsconfig.json
/tsconfig.aot.json
/webpack.config.js
Note: Structure may vary based on your application needs.
Apart from the package.json
and tsconfig.json
you will need tsconfig.aot.json
and webpack.config.js
files.
The tsconfig.aot.json
is a normal tsconfig.json
file, but with "AoT"-oriented settings.
Let's take a look at the config files:
package.json
When we type npm start in our CLI it executes both the commands. We just need to include the bundled file in or HTML and run it.
tsconfig.json
tsconfig.aot.json
What's really new is the ngc section called angularCompilerOptions. Here we say to the compiler to skip generating metadata files with the compiled application. We have also set "rootDir" which means all of our source files must be inside the folder named "app". For more information about АОТ please refer to the official "AHEAD-OF-TIME" COMPILATION cookbook.
webpack.config.js
For more information about Webpack please refer to the official guide.
Add the needed references:
Add the <my-app></my-app> tag to the body of index.html.
That's the tag where we initialize the main component.
Then import the bundled file we received after running the npm start command.
Make a reference to jqwidgets.d.ts. It contains all the TypeScript definitions for the widgets.
Import the Angular2 key components - Component, ViewChild, AfterViewInit. Then import the needed jQWidgets components.
@Component decorator:
Now it's time to create the AppComponent class.
1) @ViewChild: It holds the reference to the widget.
2) ngAfterViewInit:
All widgets have a method called createWidget that accepts either no arguments or just one - an object containing the desired settings for the widget.
If there is no argument then the widget is created through attributes.
For more information about creating jQWidgets through attributes please refer to this
guide.
We need to set an additional attribute to the angularWidget tag in order to bind to the event - onDrawEnd
"on"
before the Javascript widget event name and upperCase it's first letter.
Every widget have a method setOptions
which accepts a object as an argument. This object contains widget settings.
I. index.html
II. app.component.ts