SlideShare a Scribd company logo
for Legacy Apps
dff
HTML5 coding Hooligans!
Why Update an Old App
... and we are always learning there are better ways to do things
The Decision to “Angularize” Your App
To stay in your comfort zone is so ... comfortable.
There are always challenges in adding something entirely new to existing
code. Fear of breaking something or simple internal resistance to
change can shut down plans to modernize an app. You need strong
arguments to make the case. Fortunately AngularJS provides plenty.
Here are some of my top reasons for using it:

does not affect existing code, unless you want it to

can be completely isolated from existing code

can be controlled from existing code (have your cake and eat it too)

saves (a lot of) development time

provides a reliable path forward

helps clean up spaghetti code

make it easier to ramp-up new developers
Did you know you can use AngularJS without
drinking the kool-aid?
Just take what you want and leave the rest.
That is the beauty of AngularJS. You can integrate in small steps and
see immediate benefits without betting the farm.
Have no use for routes, services or filters. No problem! Don't want to use
Angular templates. That's OK too! You can add them anytime later if
you want.
Let the Journey Begin
Building a “Micro App” >>
Adding a “Micro-App” to Legacy HTML Code
You can specify any div as the container for your AngularJS app. To hide it from prying
eyes, just use the ng-show directive (you can also use CSS or jQuery to hide/show it).
<html>
<link rel="stylesheet" href="oldstyles.css" />
<!-- new styles for twitter bootstrap --->
<link rel="stylesheet" href="../css/bootstrap.css" />
<link rel="stylesheet" href="../font-awesome.css" />
<script src=”oldscripts.js”>
<!-- new library for bootstrap angular --->
<script type="text/javascript" src="../js/bootstrap.js"></script>
<script type="text/javascript" src="../js/angular.js"></script>
<body>
<div class=”wrapper”>
.... old code
<div ng-app="myNewAwesomeApp">
<div ng-controller=”myNewAwesomeAppController” id=”my-new-awesome-app-container”>
<div ng-show=”comeOutToPlay() == 1”>
{{myfirstvariable}} <!-- this is a variable set in your controller -->
... some other really cool stuff can go here ...
</div>
</div>
</div>
... more old code
</div>
</body></html>
The Javascript
No need to modify old javascript code. Just create add a new js file with the following.
app module
angular.module('myNewAwesomeApp', []);
controller
function myNewAwesomeAppController($scope) { // this is the controller specified in the HTML as ng-controller
$scope.myfirstvariable = 1; // this is the variable that shows up in the HTML where you have {{myfirstvariable}}
$scope.incrementMyFirstVariable= function() { // this is a function we will call from the legacy code
$scope.myfirstvariable ++;
$scope.$apply(); // this will update the HTML for you. Sit back and relax
}
$scope.comeOutToPlay= function() {
return true; // this will hake your new awesome app appear in the browser.
}
}
Call your new controller from legacy code
angular.element($("#my-new-awesome-app-container")).scope().incrementMyFirstVariable();
Too Easy?
AngularJS templates make it easier.
Adding partials views with the ng-view tag is the easiest way to insert a template.
<html>
<link rel="stylesheet" href="oldstyles.css" />
<!-- new styles for twitter bootstrap --->
<link rel="stylesheet" href="../css/bootstrap.css" />
<link rel="stylesheet" href="../font-awesome.css" />
<script src=”oldscripts.js”>
<!-- new library for bootstrap angular --->
<script type="text/javascript" src="../js/bootstrap.js"></script>
<script type="text/javascript" src="../js/angular.js"></script>
<body>
<div class=”wrapper”>
.... old code
<div ng-view></div>
... more old code
</div>
</body></html>
Now we can setup a route >
Create a Route
Originally we created a module like this:
angular.module('myNewAwesomeApp', []);
Now we can change it to this:
angular.module('myNewAwesomeApp', [], function($routeProvider, $locationProvider) {
$routeProvider.when('/myawesomenewapp', {
templateUrl: "../partials/myawesomeapp.html",
controller: myNewAwesomeAppController
}));
// Add this so your URLs will be myoldapp.com/#/myawesomenewapp rather than
myoldapp/myawesomeapp
$locationProvider.html5Mode(true);
});
Create a new HTML “partial” file (almost done) >
The Partial HTML Template
Create a new static HTML file and put it in a publicly accessible folder.
For this example, I created a file named “myawesomeapp.html” and put it in a folder called “partials'.
Here is the content of the file:
<div>
{{myfirstvariable}} <!-- this is a variable set in your controller -->
... some other really cool stuff can go here ...
</div>
Activate this view using an ordinary link pointing to the path “#/myawesomenewapp” setup in your route.
<a href=”#/myawesomenewapp”>See the Aweseome New Micro App</a>
And that is that!

More Related Content

PDF
Tek 2013 - Building Web Apps from a New Angle with AngularJS
PPTX
Don't Over-React - just use Vue!
PDF
Learning from the Best jQuery Plugins
PPTX
High Performance JavaScript (CapitolJS 2011)
KEY
New Perspectives on Performance
PDF
The Point of Vue - Intro to Vue.js
PDF
Backbone.js
PDF
jQuery Conference San Diego 2014 - Web Performance
Tek 2013 - Building Web Apps from a New Angle with AngularJS
Don't Over-React - just use Vue!
Learning from the Best jQuery Plugins
High Performance JavaScript (CapitolJS 2011)
New Perspectives on Performance
The Point of Vue - Intro to Vue.js
Backbone.js
jQuery Conference San Diego 2014 - Web Performance

What's hot (20)

PDF
AngularJS best-practices
PDF
Developing large scale JavaScript applications
PDF
Testing nightwatch, by David Torroija
PPTX
The WordPress REST API as a Springboard for Website Greatness
PDF
AngularJS performance & production tips
PDF
Javascript MVVM with Vue.JS
PDF
Get Hip with JHipster - Denver JUG 2015
PDF
Vue.js for beginners
PPTX
Building a PWA - For Everyone Who Is Scared To
PDF
PDF
Vuejs for Angular developers
PDF
Getting Started with Angular - Stormpath Webinar, January 2017
PDF
Introduction to Using PHP & MVC Frameworks
PDF
Real World Web components
PPT
jQuery For Developers Stack Overflow Dev Days Toronto
KEY
Intro To Django
PDF
Using HTML5 sensibly
PDF
On Selecting JavaScript Frameworks (Women Who Code 10/15)
PDF
Multimedia on the web - HTML5 video and audio
PDF
Front End Development for Back End Developers - vJUG24 2017
AngularJS best-practices
Developing large scale JavaScript applications
Testing nightwatch, by David Torroija
The WordPress REST API as a Springboard for Website Greatness
AngularJS performance & production tips
Javascript MVVM with Vue.JS
Get Hip with JHipster - Denver JUG 2015
Vue.js for beginners
Building a PWA - For Everyone Who Is Scared To
Vuejs for Angular developers
Getting Started with Angular - Stormpath Webinar, January 2017
Introduction to Using PHP & MVC Frameworks
Real World Web components
jQuery For Developers Stack Overflow Dev Days Toronto
Intro To Django
Using HTML5 sensibly
On Selecting JavaScript Frameworks (Women Who Code 10/15)
Multimedia on the web - HTML5 video and audio
Front End Development for Back End Developers - vJUG24 2017
Ad

Similar to AngularJS for Legacy Apps (20)

PDF
Course CodeSchool - Shaping up with Angular.js
PPTX
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
PPTX
Angular js
PPTX
Introduction to AngularJS Framework
PPTX
Introduction to AngularJS
PDF
243329387 angular-docs
PDF
AngularJS By Vipin
PPTX
AgularJS basics- angular directives and controllers
PDF
An introduction to AngularJS
PPTX
Angular Js Get Started - Complete Course
PPTX
AngularJS Introduction, how to run Angular
PPTX
Angular 6 Training with project in hyderabad india
PPTX
intro to Angular js
DOCX
ANGULAR JS LAB MANUAL(final) vtu2021 sch
PDF
Animation And Testing In AngularJS
PDF
Ionic으로 모바일앱 만들기 #3
PPTX
Angular Javascript Tutorial with command
PDF
Yeoman AngularJS and D3 - A solid stack for web apps
PDF
AngularJS 101 - Everything you need to know to get started
PPTX
Angular js
Course CodeSchool - Shaping up with Angular.js
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
Angular js
Introduction to AngularJS Framework
Introduction to AngularJS
243329387 angular-docs
AngularJS By Vipin
AgularJS basics- angular directives and controllers
An introduction to AngularJS
Angular Js Get Started - Complete Course
AngularJS Introduction, how to run Angular
Angular 6 Training with project in hyderabad india
intro to Angular js
ANGULAR JS LAB MANUAL(final) vtu2021 sch
Animation And Testing In AngularJS
Ionic으로 모바일앱 만들기 #3
Angular Javascript Tutorial with command
Yeoman AngularJS and D3 - A solid stack for web apps
AngularJS 101 - Everything you need to know to get started
Angular js
Ad

Recently uploaded (20)

PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
A Presentation on Artificial Intelligence
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
Big Data Technologies - Introduction.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Approach and Philosophy of On baking technology
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
A Presentation on Artificial Intelligence
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Empathic Computing: Creating Shared Understanding
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Network Security Unit 5.pdf for BCA BBA.
Spectral efficient network and resource selection model in 5G networks
Review of recent advances in non-invasive hemoglobin estimation
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Chapter 3 Spatial Domain Image Processing.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Big Data Technologies - Introduction.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Approach and Philosophy of On baking technology
Digital-Transformation-Roadmap-for-Companies.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Understanding_Digital_Forensics_Presentation.pptx

AngularJS for Legacy Apps

  • 1. for Legacy Apps dff HTML5 coding Hooligans!
  • 2. Why Update an Old App ... and we are always learning there are better ways to do things
  • 3. The Decision to “Angularize” Your App To stay in your comfort zone is so ... comfortable. There are always challenges in adding something entirely new to existing code. Fear of breaking something or simple internal resistance to change can shut down plans to modernize an app. You need strong arguments to make the case. Fortunately AngularJS provides plenty. Here are some of my top reasons for using it:  does not affect existing code, unless you want it to  can be completely isolated from existing code  can be controlled from existing code (have your cake and eat it too)  saves (a lot of) development time  provides a reliable path forward  helps clean up spaghetti code  make it easier to ramp-up new developers
  • 4. Did you know you can use AngularJS without drinking the kool-aid? Just take what you want and leave the rest. That is the beauty of AngularJS. You can integrate in small steps and see immediate benefits without betting the farm. Have no use for routes, services or filters. No problem! Don't want to use Angular templates. That's OK too! You can add them anytime later if you want.
  • 5. Let the Journey Begin Building a “Micro App” >>
  • 6. Adding a “Micro-App” to Legacy HTML Code You can specify any div as the container for your AngularJS app. To hide it from prying eyes, just use the ng-show directive (you can also use CSS or jQuery to hide/show it). <html> <link rel="stylesheet" href="oldstyles.css" /> <!-- new styles for twitter bootstrap ---> <link rel="stylesheet" href="../css/bootstrap.css" /> <link rel="stylesheet" href="../font-awesome.css" /> <script src=”oldscripts.js”> <!-- new library for bootstrap angular ---> <script type="text/javascript" src="../js/bootstrap.js"></script> <script type="text/javascript" src="../js/angular.js"></script> <body> <div class=”wrapper”> .... old code <div ng-app="myNewAwesomeApp"> <div ng-controller=”myNewAwesomeAppController” id=”my-new-awesome-app-container”> <div ng-show=”comeOutToPlay() == 1”> {{myfirstvariable}} <!-- this is a variable set in your controller --> ... some other really cool stuff can go here ... </div> </div> </div> ... more old code </div> </body></html>
  • 7. The Javascript No need to modify old javascript code. Just create add a new js file with the following. app module angular.module('myNewAwesomeApp', []); controller function myNewAwesomeAppController($scope) { // this is the controller specified in the HTML as ng-controller $scope.myfirstvariable = 1; // this is the variable that shows up in the HTML where you have {{myfirstvariable}} $scope.incrementMyFirstVariable= function() { // this is a function we will call from the legacy code $scope.myfirstvariable ++; $scope.$apply(); // this will update the HTML for you. Sit back and relax } $scope.comeOutToPlay= function() { return true; // this will hake your new awesome app appear in the browser. } } Call your new controller from legacy code angular.element($("#my-new-awesome-app-container")).scope().incrementMyFirstVariable();
  • 8. Too Easy? AngularJS templates make it easier. Adding partials views with the ng-view tag is the easiest way to insert a template. <html> <link rel="stylesheet" href="oldstyles.css" /> <!-- new styles for twitter bootstrap ---> <link rel="stylesheet" href="../css/bootstrap.css" /> <link rel="stylesheet" href="../font-awesome.css" /> <script src=”oldscripts.js”> <!-- new library for bootstrap angular ---> <script type="text/javascript" src="../js/bootstrap.js"></script> <script type="text/javascript" src="../js/angular.js"></script> <body> <div class=”wrapper”> .... old code <div ng-view></div> ... more old code </div> </body></html> Now we can setup a route >
  • 9. Create a Route Originally we created a module like this: angular.module('myNewAwesomeApp', []); Now we can change it to this: angular.module('myNewAwesomeApp', [], function($routeProvider, $locationProvider) { $routeProvider.when('/myawesomenewapp', { templateUrl: "../partials/myawesomeapp.html", controller: myNewAwesomeAppController })); // Add this so your URLs will be myoldapp.com/#/myawesomenewapp rather than myoldapp/myawesomeapp $locationProvider.html5Mode(true); }); Create a new HTML “partial” file (almost done) >
  • 10. The Partial HTML Template Create a new static HTML file and put it in a publicly accessible folder. For this example, I created a file named “myawesomeapp.html” and put it in a folder called “partials'. Here is the content of the file: <div> {{myfirstvariable}} <!-- this is a variable set in your controller --> ... some other really cool stuff can go here ... </div> Activate this view using an ordinary link pointing to the path “#/myawesomenewapp” setup in your route. <a href=”#/myawesomenewapp”>See the Aweseome New Micro App</a>
  • 11. And that is that!