Setting up a boilerplate for Angular 2

Introduction

I guess we all say amen to the following quote:

“The Only Thing That Is Constant Is Change” – Heraclitus

Working with XPages / IBM Notes you get scare-mongered a couple times a year thatthe whole thing is dead. With the Java vs JavaScript deathmatch not decided yet as ICS developer you might wonder on what train to jump next.

In the past I have been looking at Angular but never took it to the next level. With Angular 2 recently official released the cards might be different this time. Just look at the job vacancy sites and Angular specialists are searched after everywhere.

So I took a course Angular 2 and now I am migrating an XPages app to Angular 2 to see if the love is both directions.

Angular 2 boilerplate

A big difference with the previous version of Angular is the preparation. Angular 2 requires some sort of boilerplate, which I will describe how to build in this post.

WebContent/ODP

I will be using Domino as the HTTP server, since my data still resides in NSF. So for now my Angular app will live in the WebContent folder, so that is the working directory of my application. For ease of working I have setup a Github project. Added an ODP folder and synched my NSF with that.

In the WebContent folder in my ODP I will create the following documents:

  • tsconfig.json
  • typings.json
  • package.json
  • app/app.component.ts
  • app/main.ts
  • index.html

If you want you can just download a quickstart somewhere.

tsconfig.json

Create this file in the root of your project. In my course Typescript is used, but you could also script in Angular with JavaScript of course.

tsconfig defines the compiler configuration, here we say that our target code is JavaScript.

{
“compilerOptions”: {
“target” : “es5”,
“module” : “system”,
“moduleResolution” : “node”,
“sourceMap” : true,
“emitDecoratorMetadata” : true,
“experimentalDecorators”: true,
“removeComments” : false,
“noImplicitAny” : false
},
“exclude” : [
“node_modules”,
“typings/main”,
“typings/main.d.ts”
]
}

typings.json

Also place this file in the root of your project. In this file you define the Typescript declarations. It turns out that the Typescript compiler does not recognize several libraries…

{
“ambientDependencies”: {
“es6-shim”: “github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#7de6c3dd94feaeb21f20054b9f30d5dabc5efabd”,
“jasmine” : “github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#7de6c3dd94feaeb21f20054b9f30d5dabc5efabd”
}
}

package.json

This file will also be stored in the root of the project. In this file all dependencies and it’s versions are registered, which we will install with NPM.

packagejson

app.component.ts

An Angular 2 app needs at minimum 1 component, the root component. Components are the basic building blocks of Angular applications. A component controls a portion of the screen—a view—through its associated template.

import {Component} from ‘angular2/core’;

@Component({
selector: ‘hello-world’,
template: ‘<h1>Hello World</h1>’
})
export class AppComponent {
// … here we will add our logic later
}

So first you define a component, and then you make it available for export so you can import it into the application.

main.ts

This file is the bootstrapper in our app. Since our boilerplate is simple it does not contain so much yet:

import {bootstrap} from ‘angular2/platform/browser’
import {AppComponent} from ‘./app.component’

bootstrap(AppComponent);

Note: At this moment we do not have declared to use any module so we do not have to create an app/app.module.ts file.

index.html

The index file contains out of 2 sections, the first is the header, the other one the body. The header can be divided into 3 steps:

  • add styling
  • load the libraries
  • configure our main.js

index01

The second part is the body content of the HTML file:

index02

 

We’re done!

With this in place we have our boilerplate in place. Run “NPM install” and thereafter “NPM start” or open the index.html file on your domino server (after you have synced the files back to the NSF (this might take a while).

Also notice how the Typescript files are compiled to JavaScript files:

typescript-conversion

And finally “surprise-surprise” the result:

result-angular

Summary

Starting developing with Angular 2 is a bit different in comparison with version. Backward compatibility has always been strong for IBM Notes/Domino.

TypeScript is another opportunity for developers. I intend to blog more about my Angular journey and we’ll see how long the love will last 🙂

Here are some links of interest:

Typescript – Quick start

Angular – Quickstart

 

6 thoughts on “Setting up a boilerplate for Angular 2

    • Patrick Kwinten 2016-October-12 / 12:15 pm

      probably you do not want to repeat these steps over and over again 🙂

  1. Dexter Madronio 2016-October-26 / 12:00 pm

    Hi Patrick, I tried using the steps you’ve outlined above and find that syncing between ODP and the NSF after you’ve made changes to the ODP side takes way too long and is not optimal for development. Maybe I did it incorrectly and you have figured a way to make changes from ODP to the NSF go quicker as it takes an hour just for the sync to finish and eventually to show up on the Domino web server. Let me know how you did it in more detail. Thanks.

    BTW – It’s been awhile since your July out of work post but hope you’ve gotten new work since. And yes even in my company new Notes client application development is DEAD. An end to an era. I’ve been trying to figure out my next platform, my wife used to be in Notes is now in ServiceNow for 10 months and she’s having a blast in it. Though I think I’d rather do open source. Maybe do Angular 2 as the front end and as a lot of the companys data is still in Domino do REST calls.

    • Patrick Kwinten 2016-October-27 / 9:58 am

      hi Dexter, your findings are right. The synchronization is a pain. So rather soon I would prefer to setup an http server and use Notes/NSF just as a data-container. Have you taken a look at Cloudant/CouchDb for example? Since you are going to convert data mostly in json format anyway why not store it as json straight ahead? Could make sense. The good thing baout Notes though I find is that you have a really good client to view and manipulate the data / fields on the document if you like.

      I would go for some added services like Bluemix if I was you, hopefully you can cover the same clients/IBM customers as you do today. I have not heard of ServiceNow. I will take a look at it. Kind regards.

  2. Jenny 2016-November-16 / 8:04 pm

    Thanks for this post! I followed your directions as far as using ODP to sync with notes database. I used the files from the angular website (quick start). Everything worked as expected, until I closed the database in designer and tried to reopen. Now I cannot open the database in designer and get the error: “Insufficient memory – too many design elements”. I noticed that over 10,000 files get added to the Web Content folder! Have you come across this issue and if so, how did you get around this limitation?

Leave a reply to Stephan H. Wissel Cancel reply