Official Blog of Azilen

The Techie Explorations

How to Create an Angular 2.0 Application in Liferay DXP to Fetch the OOTB Advantages?

As techies, we always try to find out how we can use multiple collaborated technologies so that we can utilize the maximum strengths of different technologies, overcome their individual limitations and use them in creating the most suitable solution. During our research work for technologies, we have found that an Angular 2.0 application integrated with Liferay DXP offers a unique combination.

AngularJS had already been much popular among developers and enhancements of Angular 2.0 have made it even more preferred to create speedy, rich and effective applications. As we know, Angular 2.0 also requires third party tools to leverage security features, Authorization/Authentication etc. With its OOTB functionalities, Liferay DXP can be proved an ideal solution to be used with Angular 2.0 because of many reasons. Few are listed below:

  • Liferay comes with more powerful security features as portal setup in terms of creating SPA website using Angular
  • Authorization/Authentication will be managed by Liferay, no need to consider that part in Angular
  • You can use any RESTful API to load data
  • Write RESTful API in portlet and utilize it in angular services to serve CRUD data operations

In this blog, step by step we will create a simple “Hello World” Angular 2.0 App in Liferay DXP Theme. We have classified the blog in three easy steps for simplified understanding.

  • Prerequisite
  • Creation of Liferay theme
  • Adding Angular files to Liferay theme


  • You need to have the basic idea about creating a simple Angular application

If you are too new to Angular, please find the basic understanding

  • You need to have primary knowledge about creating a theme for Liferay DXP

If you are not familiar with Liferay theme creation, please
find the primary knowledge at Step by Step Guide to Create Theme for Liferay DXP.

Once you are ready with essential information, we are ready to start our actual work.

Creation of Liferay theme

Create new Liferay Theme “hello-world-theme” and deploy it

  • Create blank website “my-website” and create a public page “home”.
  • Apply newly created “hello-world-theme” to “home” page.
  • If you observe your code, you will have following structure for your newly created “hello-world-theme”:hello world theme

Adding Angular to Liferay theme

1. Now, let’s add Angular files to Liferay theme

  • Create new folder “templates” in “src” folder.
  • Go to “build” folder and copy “portal_normal.ftl” file and place it in src > templates folder.

Your “src” folder will look like image shown below.

src folder
2. Load Node Modules for Angular dependencies

  • Go to your “src” folder and create “package.json” file. Paste following code:

  • If you want to use latest packages, go to, and grab latest package.json file. Go to directory D:\ws\themes\hello-world-theme\src  in CMD and run command “npm install”

CMD and run command

Now you able to see “node_modules” folder created inside src folder.

node modules folder

You have all dependent modules installed in your theme > src > node_modules folder.

3. Create App folder inside src folder and create two files app.component.js and app.module.js.

App folder inside src

Grab code and put it in app.component.js file:

And put below code in app.module.js file:

4. Now we have some files in App and node_modules folder and the complexity is how to call files from the folders because by default Liferay provides access only to CSS, JS and Images folder.

  1. As a solution, we have to create freemarker variables to load files from App and node_modules folder.
  2. Open “portal_normal.ftl” from “templates” folder and put below code inside <head> section.

Now we have ${appPath} and ${nodeModules} path available to access files inside these folders.

5. Load libraries and app files into theme. Search for <!– inject:js–><!– endinject –> text in portal_normal.ftl.

Put the below given code between <!– inject:js–><!– endinject –>  comments.

You will be able to see the files being loaded from ${nodeModules} and ${appPath} folder.

6. It is time to load your angular app now

  • Go to <section id=”content”> in portal_normal.ftl and then insert <my-app>Loading…</my-app>

If you observe, your complete portal_normal.ftl code will look as shown below.

Once all above actions are completed, it’s time to build theme and run your App.

  1. “build” your theme
  2. “deploy” your theme
  3. Refresh your browser

And that’s done. Your first Angular 2.0 App in Liferay DXP is ready now.

first Angular 2.0 App in Liferay DXP

Liferay DXP can make your Angular 2.0 application much secured. Its OOTB features and functionalities save you from lot of code work and they easily can be integrated with Angular 2.0 app. It will offer quick and rich user experience to the user. As a matter of fact, Liferay DXP has got potential to offer robust and highly scalable technology solutions. If researched and executed well, it can empower other technologies as well.

If you longing to learn more, please mail us your query.

Leave a reply