node -v
in cmd. It will output the current version.Note: Make sure that you are running on the latest NodeJS
and npm
versions.
The guide below is based on the Angular2 Just-in-time (JiT) compilation, which is the simplest one.
For Ahead-of-time (AoT) compilation, please refer to this guide.
You can find out about the differences here: Ahead-of-time (AoT) vs Just-in-time (JiT)
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
/index.html
/package.json
/tsconfig.json
/systemjs.config.js
Note: Structure may vary based on your application needs.
First we need to install the Angular 2 and Typescript required modules. For that we need a package.json file. Here is ours:
After your package.json is ready type npm install in your CLI.
Then we need to configure the tsconfig.json file:
And finally the system.config.js file:
Note: Configuration may vary based on your application needs.
Note: Here we use JIT
compilation which means that our 'TypeScript' files are compiled in run time.
If you want your 'TypeScript' files to be transpiled to 'JavaScript' before run time please refer to Angular 2 Ahead-of-time (AoT) compiler.
Add the needed references:
Import main.ts to index.html:
Add the <my-app></my-app> tag to the body of index.html. That's the tag where we initialize the main component.
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 - onClick
"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
This is another way of initializing a jQWidget.
Here we set the options in the tag itself as attributes. Lets take a look:
Properties names are put in square brackets []
and we can choose either to put the value
direcly like in the width, height and colorScheme
properties or get it from a property in our class - like in the max, values and tooltip
properties.
Here is our class:
All of the these three can be done the same way as in the normal initialization, but also the properties which values we defined in our class can be changed directly:
This will altomaticly update them.
Note: Angular 2 is supported only in modern web browsers such as: Chrome, Firefox, Edge and IE11.
For IE11 you must use transpiled JavaScript files.
You can compile the app in the browser, at runtime, as the application loads, using the Just-in-time (JiT) compiler. But there is another way called "Ahead-of-time (AoT)" compilation which as said in Angular2 official site: "radically improves performance". Here we covert 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 (AoT)" 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
We often want to both display a data property and update that property when the user makes changes.
Let's take a look at the following example.
app.component.ts:
When we type inside the input field the country variable is automatically updated.
Let`s take a look:
Important: If you are using any of the Input
based widgets like jqxInput,
jqxComplexInput, jqxDateTimeInput and so on you must import the FormsModule
in your app.module.ts
file and add it to the @NgModel:
If you won't be using the Two Way Data Binding ,
remove the ngModel
and all it`s needed code from the
relevant angular_xxxx.ts
file: