This blog is about creation of a ‘Hello World’ Angular 2.0 Application integrated with Liferay DXP to fetch Liferay’s OOTB advantages. Such integration can enable quick development of secured application that provides boosted digital experience to the user.
The Codex of Business Writing Software for Real-World Solutions 2.pptx
How to create an angular 2.0 application in liferay dxp to fetch the ootb advantages
1. How to Create an Angular 2.0 Application in Liferay DXP to Fetch the
OOTB Advantages?
2. Intro
There have been years since technology has been instigating innovations for
the civilizations. That’s what we have been relating to something called
development. And we are now in a century where technology has reached to
an extent with such inventions that were unthinkable before. Virtual Reality
for instance is one of the aspects in this case. This is the science which deals
with the facets that actually do not exist!
3. 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
4. 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
Prerequisite:
• 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 https://angular.io/docs/js/latest/quickstart.html
• You need to have primary knowledge about creating a theme for Liferay
DXP
5. 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.
6. 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”:
7.
8. 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.
9.
10. 2. Load Node Modules for Angular dependencies
• Go to your “src” folder and create “package.json” file. Paste following code:
11. • If you want to use latest packages, go to Angular.io, and grab latest
package.json file. Go to directory D:wsthemeshello-world-themesrc in
CMD and run command “npm install”
12. Now you able to see “node_modules” folder created inside “src” folder.
You have all dependent modules installed in your theme > src > node_modules
folder.
13. • 3. Create “App” folder inside “src” folder and create two
files app.component.js and app.module.js.
16. 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.
• As a solution, we have to create freemarker variables to load files
from “App” and “node_modules” folder.
• Open “portal_normal.ftl” from “templates” folder and put below code
inside <head> section.
17. 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.
18.
19. • 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.
20.
21.
22.
23. Once all above actions are completed, it’s time to build theme and run your
App.
• “build” your theme
• “deploy” your theme
• Refresh your browser
And that’s done. Your first Angular 2.0 App in Liferay DXP is ready now.
24.
25. 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.