SlideShare a Scribd company logo
02 AngularJS
Framework Analysis
Public Code Repository




                                                               by
                                          Sergey N. Bolshchikov
                                           http://bolshchikov.net
                         sergey.bolshchikov@new-proimage.com
                                           New ProImage, 2012
Outline
 I.   Introduction
II.   Philosophy
Outline
 I.   Introduction
II.   Philosophy



                                     ay
                                  od
                               et
                           tlin in
                         ou ive
                     No t d
                      J us
Introduction
I want to build well structured and dynamic web application.

Header-Navigation Bar


                    Content Wrapper
    click

                                  click

 Tree
                        Content




Footer
Introduction
Traditional solution:




              < 37%
                        > 63% LOC
               LOC
                        Javascript
              HTML
Philosophy
●   Angular is what HTML could have been if it had been designed for
    applications.

●   HTML is a great declarative language for static documents. It does not
    contain much in the way of creating application.

●   Building web-applications is an exercise in what do I have to do, so that I
    trick the browser in to do what I want.

●   That's why we have frameworks - set of utility functions and libraries for
    DOM manipulation.

●   Angular takes another approach.

●   Angular teaches the browser new syntax.
Introduction
AngularJS solution:




                          > 41%
              < 59% LOC    LOC
                 HTML      Java
                          script
Static HTML
<!doctype html>
<html lang="en" ng-app>
<head>
  <meta charset="utf-8">
  <title>My AngularJS App</title>
</head>
<body>
  <table class="table table-stripped">
    <thead>
      <tr>
          <th>ID</th><th>Complete</th><th>Name</th><th>Deadline</th>
      </tr>
    </thead>
    <tbody>
        <tr>
            <td>1001</td><td>false</td><td>Do Groceries</td><td>01/08/12</td>
        </tr>
        <tr>
            <td>1002</td><td>false</td><td>Barber the cat</td><td>01/08/12</td>
        </tr>
    </tbody>
  </table>
</body>
</html>
​


                                                                         See example live
Declarative HTML
<!doctype html>
<html lang="en" ng-app>
<head>
  <meta charset="utf-8">
  <title>My AngularJS App</title>
</head>
<body>
  <table class="table table-stripped" ng-controller="TodoCtrl">
    <thead>
      <tr>
          <th>ID</th><th>Complete</th><th>Name</th><th>Deadline</th>
      </tr>
    </thead>
    <tbody>
        <tr ng-repeat="todo in todos">
          <td ng-click="setTrue(todo.id)">{{todo.id}}</td>
          <td>{{todo.done}}</td>
          <td>{{todo.name}}</td>
          <td>{{todo.deadline}}</td>
        </tr>
    </tbody>
  </table>

</body>
</html>
​
​                                                                      See example live
Declarative HTML
<!doctype html>
<html lang="en" ng-app>
<head>
  <meta charset="utf-8">
  <title>My AngularJS App</title>
</head>
<body>
  <table class="table table-stripped" ng-controller="TodoCtrl">
    <thead>
       <tr>
           <th>ID</th><th>Complete</th><th>Name</th><th>Deadline</th>
       </tr>
    </thead>
    <tbody>
         <tr ng-repeat="todo in todos">
           <td ng-click="setTrue(todo.id)">{{todo.id}}</td>
           <td>{{todo.done}}</td>
           <td>{{todo.name}}</td>
           <td>{{todo.deadline}}</td>
         </tr>
    </tbody>
  </table>

</body>
</html>
​
​
Declarative HTML
<!doctype html>
<html lang="en" ng-app>
<head>
  <meta charset="utf-8">
  <title>My AngularJS App</title>
</head>
<body>
  <table class="table table-stripped" ng-controller="TodoCtrl">
    <thead>
       <tr>
           <th>ID</th><th>Complete</th><th>Name</th><th>Deadline</th>
       </tr>
    </thead>
    <tbody>
         <tr ng-repeat="todo in todos">
           <td ng-click="setTrue(todo.id)">{{todo.id}}</td>
           <td>{{todo.done}}</td>
           <td>{{todo.name}}</td>
           <td>{{todo.deadline}}</td>
         </tr>
    </tbody>
  </table>

</body>
</html>
​
​
Declarative HTML
<!doctype html>
<html lang="en" ng-app>
<head>
  <meta charset="utf-8">
  <title>My AngularJS App</title>
</head>
<body>
  <table class="table table-stripped" ng-controller="TodoCtrl">
    <thead>
       <tr>
           <th>ID</th><th>Complete</th><th>Name</th><th>Deadline</th>
       </tr>
    </thead>
    <tbody>
         <tr ng-repeat="todo in todos">
           <td ng-click="setTrue(todo.id)">{{todo.id}}</td>
           <td>{{todo.done}}</td>
           <td>{{todo.name}}</td>
           <td>{{todo.deadline}}</td>
         </tr>
    </tbody>
  </table>

</body>
</html>
​
​
Declarative HTML
<!doctype html>
<html lang="en" ng-app>
<head>
  <meta charset="utf-8">
  <title>My AngularJS App</title>
</head>
<body>
  <table class="table table-stripped" ng-controller="TodoCtrl">
    <thead>
       <tr>
           <th>ID</th><th>Complete</th><th>Name</th><th>Deadline</th>
       </tr>
    </thead>
    <tbody>
         <tr ng-repeat="todo in todos">
           <td ng-click="setTrue(todo.id)">{{todo.id}}</td>
            <td>{{todo.done}}</td>
           <td>{{todo.name}}</td>
           <td>{{todo.deadline}}</td>
         </tr>
    </tbody>
  </table>

</body>
</html>
​
​
MVC
Angular says:
"There are many ways to structure the code for an
application.
For Angular apps, we encourage the use of the Model-
View-Controller (MVC) design pattern to decouple the code
and to separate concerns.
With that in mind, let's use a little Angular and JavaScript to
add model, view, and controller components to our app."
Controller
○ a controller is a JavaScript function

○ It contains data

○ It specifies the behavior

○ It should contain only the business logic needed for a
  single view.
Controller
<table class="table table-stripped" ng-controller="TodoCtrl">
function TodoCtrl(scope) {
    scope.todos = [
    {
        'id': 1001,
        'done': false,
        'name': 'Do Groceries',
        'deadline': new Date()
    },
    {
        'id': 1002,
        'done': false,
        'name': 'Barber the cat',
        'deadline': new Date()
    }];
    scope.setTrue = function(id) {
        var el = (function(id){
            for (var i=0; i<scope.todos.length; i++) {
                if (scope.todos[i].id === id) {
                    return scope.todos[i]
                }
            }
        })(id);
        el.done = true;
    }
}
TodoCtrl.$inject = ['$scope'];
Controller
<table class="table table-stripped" ng-controller="TodoCtrl">
function TodoCtrl(scope) {
    scope.todos = [
    {
        'id': 1001,
        'done': false,
        'name': 'Do Groceries',
        'deadline': new Date()
    },
    {
        'id': 1002,
        'done': false,
        'name': 'Barber the cat',
        'deadline': new Date()
    }];
    scope.setTrue = function(id) {
        var el = (function(id){
            for (var i=0; i<scope.todos.length; i++) {
                if (scope.todos[i].id === id) {
                    return scope.todos[i]
                }
            }
        })(id);
        el.done = true;
    }
}
TodoCtrl.$inject = ['$scope'];
Controller
<table class="table table-stripped" ng-controller="TodoCtrl">
function TodoCtrl(scope) {
    scope.todos = [
    {
        'id': 1001,
        'done': false,
        'name': 'Do Groceries',
        'deadline': new Date()
    },
    {
        'id': 1002,
        'done': false,
        'name': 'Barber the cat',
        'deadline': new Date()
    }];
    scope.setTrue = function(id) {
        var el = (function(id){
            for (var i=0; i<scope.todos.length; i++) {
                if (scope.todos[i].id === id) {
                    return scope.todos[i]
                }
            }
        })(id);
        el.done = true;
    }
}
TodoCtrl.$inject = ['$scope'];
Scope
○ an object that refers to the application model
  (application itself)

○ an execution context for expressions like
  {{ todo.name }}

○ Scopes are arranged in hierarchical structure which
  mimic the DOM structure of the application

○ Scopes can watch expressions and propagate events
Scope
<html ng-app>                        root
                                    Scope
                                                                             01/
                                                1001   false     Groceries
                                                                             08
<table ng-controller="TodoCtrl">
                                                                             01/
                                   TodoCtrl     1002   false      Barber
                                                                             08
  <tr ng-repeat="todo in todos">    Scope


          <td>{{todo.id}}</td>

                                   Repeater
       </tr>                         Repeater
                                    Scope
                                      Scope

   </table>



</html>

            Template               Model                       View
Controller
<table class="table table-stripped" ng-controller="TodoCtrl">
function TodoCtrl(scope) {
    scope.todos = [
    {
        'id': 1001,
        'done': false,
        'name': 'Do Groceries',
        'deadline': new Date()
    },
    {
        'id': 1002,
        'done': false,
        'name': 'Barber the cat',
        'deadline': new Date()
    }];
    scope.setTrue = function(id) {
        var el = (function(id){
            for (var i=0; i<scope.todos.length; i++) {
                if (scope.todos[i].id === id) {
                    return scope.todos[i]
                }
            }
        })(id);
        el.done = true;
    }
}
TodoCtrl.$inject = ['$scope'];
Model: attrs of Scope
<table class="table table-stripped" ng-controller="TodoCtrl">
function TodoCtrl(scope) {
    scope.todos = [
    {                                           Model
        'id': 1001,
        'done': false,
        'name': 'Do Groceries',
        'deadline': new Date()
    },
    {
        'id': 1002,
        'done': false,
        'name': 'Barber the cat',
        'deadline': new Date()
    }];
    scope.setTrue = function(id) {
        var el = (function(id){
            for (var i=0; i<scope.todos.length; i++) {
                if (scope.todos[i].id === id) {
                    return scope.todos[i]
                }
            }
        })(id);
        el.done = true;
    }
}
TodoCtrl.$inject = ['$scope'];
Template
<!doctype html>
<html lang="en" ng-app>
<head>
  <meta charset="utf-8">
  <title>My AngularJS App</title>
</head>
<body>
  <table class="table table-stripped" ng-controller="TodoCtrl">
    <thead>
       <tr>
           <th>ID</th><th>Complete</th><th>Name</th><th>Deadline</th>
       </tr>
    </thead>
    <tbody>
         <tr ng-repeat="todo in todos">
           <td ng-click="setTrue(todo.id)">{{todo.id}}</td>
           <td>{{todo.done}}</td>
           <td>{{todo.name}}</td>
           <td>{{todo.deadline}}</td>
         </tr>
    </tbody>
  </table>

</body>
</html>
​
​
Data-binding and interaction




See live example
Routing


angular.module('myApp').
    config(['$routeProvider' ,
         function($routeProvider ) {
             $routeProvider .when(
                 '/folder/:name' ,
                 {templateUrl : 'partials/folder.html' ,
                 controller : FolderCtrl
         });
    }])​
Performance
●   Browser support: IE 8+, Chrome, FF, Safari, Opera

●   Framework size: 503KB

●   Application size: 756KB

More Related Content

PDF
AngularJS Framework
Barcamp Saigon
 
ODP
AngularJs Crash Course
Keith Bloomfield
 
PDF
AngularJS Basic Training
Cornel Stefanache
 
PPTX
AngularJS Architecture
Eyal Vardi
 
PPTX
AngularJs
syam kumar kk
 
PPTX
AngularJS Internal
Eyal Vardi
 
PPTX
AngularJS Directives
Eyal Vardi
 
PPTX
Practical AngularJS
Wei Ru
 
AngularJS Framework
Barcamp Saigon
 
AngularJs Crash Course
Keith Bloomfield
 
AngularJS Basic Training
Cornel Stefanache
 
AngularJS Architecture
Eyal Vardi
 
AngularJs
syam kumar kk
 
AngularJS Internal
Eyal Vardi
 
AngularJS Directives
Eyal Vardi
 
Practical AngularJS
Wei Ru
 

What's hot (20)

PDF
Workshop 12: AngularJS Parte I
Visual Engineering
 
PPTX
Angularjs Basics
Anuradha Bandara
 
PPTX
AngularJs $provide API internals & circular dependency problem.
Yan Yankowski
 
PDF
Building scalable applications with angular js
Andrew Alpert
 
PPTX
AngularJS with TypeScript and Windows Azure Mobile Services
Rainer Stropek
 
PPTX
AngularJS in 60ish Minutes
Dan Wahlin
 
PDF
GDayX - Advanced Angular.JS
Nicolas Embleton
 
PDF
Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...
FalafelSoftware
 
PDF
준비하세요 Angular js 2.0
Jeado Ko
 
PPTX
AngularJS $Provide Service
Eyal Vardi
 
PDF
Workshop 8: Templating: Handlebars, DustJS
Visual Engineering
 
PDF
Intro to Angular.JS Directives
Christian Lilley
 
PPTX
AngularJS Animations
Eyal Vardi
 
DOCX
Filters in AngularJS
Brajesh Yadav
 
PPTX
Modules and injector
Eyal Vardi
 
PPTX
Upgrading from Angular 1.x to Angular 2.x
Eyal Vardi
 
PDF
Difference between java script and jquery
Umar Ali
 
PDF
[FEConf Korea 2017]Angular 컴포넌트 대화법
Jeado Ko
 
PPTX
Building AngularJS Custom Directives
Dan Wahlin
 
PPTX
Workshop 1: Good practices in JavaScript
Visual Engineering
 
Workshop 12: AngularJS Parte I
Visual Engineering
 
Angularjs Basics
Anuradha Bandara
 
AngularJs $provide API internals & circular dependency problem.
Yan Yankowski
 
Building scalable applications with angular js
Andrew Alpert
 
AngularJS with TypeScript and Windows Azure Mobile Services
Rainer Stropek
 
AngularJS in 60ish Minutes
Dan Wahlin
 
GDayX - Advanced Angular.JS
Nicolas Embleton
 
Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...
FalafelSoftware
 
준비하세요 Angular js 2.0
Jeado Ko
 
AngularJS $Provide Service
Eyal Vardi
 
Workshop 8: Templating: Handlebars, DustJS
Visual Engineering
 
Intro to Angular.JS Directives
Christian Lilley
 
AngularJS Animations
Eyal Vardi
 
Filters in AngularJS
Brajesh Yadav
 
Modules and injector
Eyal Vardi
 
Upgrading from Angular 1.x to Angular 2.x
Eyal Vardi
 
Difference between java script and jquery
Umar Ali
 
[FEConf Korea 2017]Angular 컴포넌트 대화법
Jeado Ko
 
Building AngularJS Custom Directives
Dan Wahlin
 
Workshop 1: Good practices in JavaScript
Visual Engineering
 
Ad

Viewers also liked (17)

PPTX
Introduction to Angularjs
Manish Shekhawat
 
PDF
AngularJS 101 - Everything you need to know to get started
Stéphane Bégaudeau
 
ODP
Introduction to Angular 2
Knoldus Inc.
 
PDF
스프링보다 중요한 스프링 이야기
Sungchul Park
 
PDF
Ember.js - A JavaScript framework for creating ambitious web applications
Juliana Lucena
 
PDF
Introduction To Single Page Application
KMS Technology
 
PPT
Get MEAN! Node.js and the MEAN stack
Nicholas McClay
 
PPTX
Building single page applications
SC5.io
 
PDF
Single Page Applications
Massimo Iacolare
 
PPT
The MEAN Stack: MongoDB, ExpressJS, AngularJS and Node.js
MongoDB
 
PPTX
Single Page Application (SPA) using AngularJS
M R Rony
 
PDF
MEAN Stack
Krishnaprasad k
 
PPT
Single Page Application presentation
John Staveley
 
PDF
Does my DIV look big in this?
glen_a_smith
 
PDF
Introduction to the MEAN stack
Yoann Gotthilf
 
PDF
AngularJS application architecture
Gabriele Falace
 
PDF
SlideShare 101
Amit Ranjan
 
Introduction to Angularjs
Manish Shekhawat
 
AngularJS 101 - Everything you need to know to get started
Stéphane Bégaudeau
 
Introduction to Angular 2
Knoldus Inc.
 
스프링보다 중요한 스프링 이야기
Sungchul Park
 
Ember.js - A JavaScript framework for creating ambitious web applications
Juliana Lucena
 
Introduction To Single Page Application
KMS Technology
 
Get MEAN! Node.js and the MEAN stack
Nicholas McClay
 
Building single page applications
SC5.io
 
Single Page Applications
Massimo Iacolare
 
The MEAN Stack: MongoDB, ExpressJS, AngularJS and Node.js
MongoDB
 
Single Page Application (SPA) using AngularJS
M R Rony
 
MEAN Stack
Krishnaprasad k
 
Single Page Application presentation
John Staveley
 
Does my DIV look big in this?
glen_a_smith
 
Introduction to the MEAN stack
Yoann Gotthilf
 
AngularJS application architecture
Gabriele Falace
 
SlideShare 101
Amit Ranjan
 
Ad

Similar to AngularJS Basics with Example (20)

PDF
Angular js - 4developers 12 kwietnia 2013
Marcin Wosinek
 
PPT
AngularJS Mobile Warsaw 20-10-2014
Dariusz Kalbarczyk
 
PDF
Introduction to AngularJS
Marco Vito Moscaritolo
 
PDF
Introduction to angular js
Marco Vito Moscaritolo
 
DOCX
Built in filters
Brajesh Yadav
 
PPTX
AngularJS
LearningTech
 
PPTX
Angular js
ParmarAnisha
 
PDF
Vaadin Components @ Angular U
Joonas Lehtinen
 
PPTX
JavaScript lesson 1.pptx
MuqaddarNiazi1
 
PDF
Building Reusable Custom Elements With Angular
Ilia Idakiev
 
PDF
Pengenalan AngularJS
Edi Santoso
 
PPT
What you forgot from your Computer Science Degree
Stephen Darlington
 
KEY
Summer - The HTML5 Library for Java and Scala
rostislav
 
DOCX
Controller in AngularJS
Brajesh Yadav
 
DOCX
Angular js
prasaddammalapati
 
PPTX
Rails, Postgres, Angular, and Bootstrap: The Power Stack
David Copeland
 
KEY
网站无障碍阅读知识
ppanyong
 
KEY
网站无障碍阅读知识
ppanyong
 
PDF
Reactive Type-safe WebComponents
Martin Hochel
 
PDF
Angular.js is super cool
Maksym Hopei
 
Angular js - 4developers 12 kwietnia 2013
Marcin Wosinek
 
AngularJS Mobile Warsaw 20-10-2014
Dariusz Kalbarczyk
 
Introduction to AngularJS
Marco Vito Moscaritolo
 
Introduction to angular js
Marco Vito Moscaritolo
 
Built in filters
Brajesh Yadav
 
AngularJS
LearningTech
 
Angular js
ParmarAnisha
 
Vaadin Components @ Angular U
Joonas Lehtinen
 
JavaScript lesson 1.pptx
MuqaddarNiazi1
 
Building Reusable Custom Elements With Angular
Ilia Idakiev
 
Pengenalan AngularJS
Edi Santoso
 
What you forgot from your Computer Science Degree
Stephen Darlington
 
Summer - The HTML5 Library for Java and Scala
rostislav
 
Controller in AngularJS
Brajesh Yadav
 
Angular js
prasaddammalapati
 
Rails, Postgres, Angular, and Bootstrap: The Power Stack
David Copeland
 
网站无障碍阅读知识
ppanyong
 
网站无障碍阅读知识
ppanyong
 
Reactive Type-safe WebComponents
Martin Hochel
 
Angular.js is super cool
Maksym Hopei
 

More from Sergey Bolshchikov (14)

PDF
Onboarding for Software Engineers Done Right
Sergey Bolshchikov
 
PDF
Pragmatic React Workshop
Sergey Bolshchikov
 
PDF
Microservices on the client side
Sergey Bolshchikov
 
PDF
ES2015 Quiz
Sergey Bolshchikov
 
PDF
Talking code: How To
Sergey Bolshchikov
 
PPTX
Values & Culture of Continuous Deliver
Sergey Bolshchikov
 
PDF
Protractor: Tips & Tricks
Sergey Bolshchikov
 
PDF
Continuous Delivery for Front-End Engineers
Sergey Bolshchikov
 
PDF
Зачем нужен EmberJS, если мне хвататет jQuery
Sergey Bolshchikov
 
PDF
Ember Reusable Components and Widgets
Sergey Bolshchikov
 
PDF
Front End Development: The Important Parts
Sergey Bolshchikov
 
PDF
Web Projects: From Theory To Practice
Sergey Bolshchikov
 
PDF
Backbone Basics with Examples
Sergey Bolshchikov
 
PDF
JS Single-Page Web App Essentials
Sergey Bolshchikov
 
Onboarding for Software Engineers Done Right
Sergey Bolshchikov
 
Pragmatic React Workshop
Sergey Bolshchikov
 
Microservices on the client side
Sergey Bolshchikov
 
ES2015 Quiz
Sergey Bolshchikov
 
Talking code: How To
Sergey Bolshchikov
 
Values & Culture of Continuous Deliver
Sergey Bolshchikov
 
Protractor: Tips & Tricks
Sergey Bolshchikov
 
Continuous Delivery for Front-End Engineers
Sergey Bolshchikov
 
Зачем нужен EmberJS, если мне хвататет jQuery
Sergey Bolshchikov
 
Ember Reusable Components and Widgets
Sergey Bolshchikov
 
Front End Development: The Important Parts
Sergey Bolshchikov
 
Web Projects: From Theory To Practice
Sergey Bolshchikov
 
Backbone Basics with Examples
Sergey Bolshchikov
 
JS Single-Page Web App Essentials
Sergey Bolshchikov
 

Recently uploaded (20)

PDF
Architecture of the Future (09152021)
EdwardMeyman
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
Beyond Automation: The Role of IoT Sensor Integration in Next-Gen Industries
Rejig Digital
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
Software Development Company | KodekX
KodekX
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PPTX
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
PPTX
IoT Sensor Integration 2025 Powering Smart Tech and Industrial Automation.pptx
Rejig Digital
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
PDF
This slide provides an overview Technology
mineshkharadi333
 
Architecture of the Future (09152021)
EdwardMeyman
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Beyond Automation: The Role of IoT Sensor Integration in Next-Gen Industries
Rejig Digital
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
Software Development Company | KodekX
KodekX
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
IoT Sensor Integration 2025 Powering Smart Tech and Industrial Automation.pptx
Rejig Digital
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
This slide provides an overview Technology
mineshkharadi333
 

AngularJS Basics with Example

  • 1. 02 AngularJS Framework Analysis Public Code Repository by Sergey N. Bolshchikov http://bolshchikov.net [email protected] New ProImage, 2012
  • 2. Outline I. Introduction II. Philosophy
  • 3. Outline I. Introduction II. Philosophy ay od et tlin in ou ive No t d J us
  • 4. Introduction I want to build well structured and dynamic web application. Header-Navigation Bar Content Wrapper click click Tree Content Footer
  • 5. Introduction Traditional solution: < 37% > 63% LOC LOC Javascript HTML
  • 6. Philosophy ● Angular is what HTML could have been if it had been designed for applications. ● HTML is a great declarative language for static documents. It does not contain much in the way of creating application. ● Building web-applications is an exercise in what do I have to do, so that I trick the browser in to do what I want. ● That's why we have frameworks - set of utility functions and libraries for DOM manipulation. ● Angular takes another approach. ● Angular teaches the browser new syntax.
  • 7. Introduction AngularJS solution: > 41% < 59% LOC LOC HTML Java script
  • 8. Static HTML <!doctype html> <html lang="en" ng-app> <head> <meta charset="utf-8"> <title>My AngularJS App</title> </head> <body> <table class="table table-stripped"> <thead> <tr> <th>ID</th><th>Complete</th><th>Name</th><th>Deadline</th> </tr> </thead> <tbody> <tr> <td>1001</td><td>false</td><td>Do Groceries</td><td>01/08/12</td> </tr> <tr> <td>1002</td><td>false</td><td>Barber the cat</td><td>01/08/12</td> </tr> </tbody> </table> </body> </html> ​ See example live
  • 9. Declarative HTML <!doctype html> <html lang="en" ng-app> <head> <meta charset="utf-8"> <title>My AngularJS App</title> </head> <body> <table class="table table-stripped" ng-controller="TodoCtrl"> <thead> <tr> <th>ID</th><th>Complete</th><th>Name</th><th>Deadline</th> </tr> </thead> <tbody> <tr ng-repeat="todo in todos"> <td ng-click="setTrue(todo.id)">{{todo.id}}</td> <td>{{todo.done}}</td> <td>{{todo.name}}</td> <td>{{todo.deadline}}</td> </tr> </tbody> </table> </body> </html> ​ ​ See example live
  • 10. Declarative HTML <!doctype html> <html lang="en" ng-app> <head> <meta charset="utf-8"> <title>My AngularJS App</title> </head> <body> <table class="table table-stripped" ng-controller="TodoCtrl"> <thead> <tr> <th>ID</th><th>Complete</th><th>Name</th><th>Deadline</th> </tr> </thead> <tbody> <tr ng-repeat="todo in todos"> <td ng-click="setTrue(todo.id)">{{todo.id}}</td> <td>{{todo.done}}</td> <td>{{todo.name}}</td> <td>{{todo.deadline}}</td> </tr> </tbody> </table> </body> </html> ​ ​
  • 11. Declarative HTML <!doctype html> <html lang="en" ng-app> <head> <meta charset="utf-8"> <title>My AngularJS App</title> </head> <body> <table class="table table-stripped" ng-controller="TodoCtrl"> <thead> <tr> <th>ID</th><th>Complete</th><th>Name</th><th>Deadline</th> </tr> </thead> <tbody> <tr ng-repeat="todo in todos"> <td ng-click="setTrue(todo.id)">{{todo.id}}</td> <td>{{todo.done}}</td> <td>{{todo.name}}</td> <td>{{todo.deadline}}</td> </tr> </tbody> </table> </body> </html> ​ ​
  • 12. Declarative HTML <!doctype html> <html lang="en" ng-app> <head> <meta charset="utf-8"> <title>My AngularJS App</title> </head> <body> <table class="table table-stripped" ng-controller="TodoCtrl"> <thead> <tr> <th>ID</th><th>Complete</th><th>Name</th><th>Deadline</th> </tr> </thead> <tbody> <tr ng-repeat="todo in todos"> <td ng-click="setTrue(todo.id)">{{todo.id}}</td> <td>{{todo.done}}</td> <td>{{todo.name}}</td> <td>{{todo.deadline}}</td> </tr> </tbody> </table> </body> </html> ​ ​
  • 13. Declarative HTML <!doctype html> <html lang="en" ng-app> <head> <meta charset="utf-8"> <title>My AngularJS App</title> </head> <body> <table class="table table-stripped" ng-controller="TodoCtrl"> <thead> <tr> <th>ID</th><th>Complete</th><th>Name</th><th>Deadline</th> </tr> </thead> <tbody> <tr ng-repeat="todo in todos"> <td ng-click="setTrue(todo.id)">{{todo.id}}</td> <td>{{todo.done}}</td> <td>{{todo.name}}</td> <td>{{todo.deadline}}</td> </tr> </tbody> </table> </body> </html> ​ ​
  • 14. MVC Angular says: "There are many ways to structure the code for an application. For Angular apps, we encourage the use of the Model- View-Controller (MVC) design pattern to decouple the code and to separate concerns. With that in mind, let's use a little Angular and JavaScript to add model, view, and controller components to our app."
  • 15. Controller ○ a controller is a JavaScript function ○ It contains data ○ It specifies the behavior ○ It should contain only the business logic needed for a single view.
  • 16. Controller <table class="table table-stripped" ng-controller="TodoCtrl"> function TodoCtrl(scope) { scope.todos = [ { 'id': 1001, 'done': false, 'name': 'Do Groceries', 'deadline': new Date() }, { 'id': 1002, 'done': false, 'name': 'Barber the cat', 'deadline': new Date() }]; scope.setTrue = function(id) { var el = (function(id){ for (var i=0; i<scope.todos.length; i++) { if (scope.todos[i].id === id) { return scope.todos[i] } } })(id); el.done = true; } } TodoCtrl.$inject = ['$scope'];
  • 17. Controller <table class="table table-stripped" ng-controller="TodoCtrl"> function TodoCtrl(scope) { scope.todos = [ { 'id': 1001, 'done': false, 'name': 'Do Groceries', 'deadline': new Date() }, { 'id': 1002, 'done': false, 'name': 'Barber the cat', 'deadline': new Date() }]; scope.setTrue = function(id) { var el = (function(id){ for (var i=0; i<scope.todos.length; i++) { if (scope.todos[i].id === id) { return scope.todos[i] } } })(id); el.done = true; } } TodoCtrl.$inject = ['$scope'];
  • 18. Controller <table class="table table-stripped" ng-controller="TodoCtrl"> function TodoCtrl(scope) { scope.todos = [ { 'id': 1001, 'done': false, 'name': 'Do Groceries', 'deadline': new Date() }, { 'id': 1002, 'done': false, 'name': 'Barber the cat', 'deadline': new Date() }]; scope.setTrue = function(id) { var el = (function(id){ for (var i=0; i<scope.todos.length; i++) { if (scope.todos[i].id === id) { return scope.todos[i] } } })(id); el.done = true; } } TodoCtrl.$inject = ['$scope'];
  • 19. Scope ○ an object that refers to the application model (application itself) ○ an execution context for expressions like {{ todo.name }} ○ Scopes are arranged in hierarchical structure which mimic the DOM structure of the application ○ Scopes can watch expressions and propagate events
  • 20. Scope <html ng-app> root Scope 01/ 1001 false Groceries 08 <table ng-controller="TodoCtrl"> 01/ TodoCtrl 1002 false Barber 08 <tr ng-repeat="todo in todos"> Scope <td>{{todo.id}}</td> Repeater </tr> Repeater Scope Scope </table> </html> Template Model View
  • 21. Controller <table class="table table-stripped" ng-controller="TodoCtrl"> function TodoCtrl(scope) { scope.todos = [ { 'id': 1001, 'done': false, 'name': 'Do Groceries', 'deadline': new Date() }, { 'id': 1002, 'done': false, 'name': 'Barber the cat', 'deadline': new Date() }]; scope.setTrue = function(id) { var el = (function(id){ for (var i=0; i<scope.todos.length; i++) { if (scope.todos[i].id === id) { return scope.todos[i] } } })(id); el.done = true; } } TodoCtrl.$inject = ['$scope'];
  • 22. Model: attrs of Scope <table class="table table-stripped" ng-controller="TodoCtrl"> function TodoCtrl(scope) { scope.todos = [ { Model 'id': 1001, 'done': false, 'name': 'Do Groceries', 'deadline': new Date() }, { 'id': 1002, 'done': false, 'name': 'Barber the cat', 'deadline': new Date() }]; scope.setTrue = function(id) { var el = (function(id){ for (var i=0; i<scope.todos.length; i++) { if (scope.todos[i].id === id) { return scope.todos[i] } } })(id); el.done = true; } } TodoCtrl.$inject = ['$scope'];
  • 23. Template <!doctype html> <html lang="en" ng-app> <head> <meta charset="utf-8"> <title>My AngularJS App</title> </head> <body> <table class="table table-stripped" ng-controller="TodoCtrl"> <thead> <tr> <th>ID</th><th>Complete</th><th>Name</th><th>Deadline</th> </tr> </thead> <tbody> <tr ng-repeat="todo in todos"> <td ng-click="setTrue(todo.id)">{{todo.id}}</td> <td>{{todo.done}}</td> <td>{{todo.name}}</td> <td>{{todo.deadline}}</td> </tr> </tbody> </table> </body> </html> ​ ​
  • 25. Routing angular.module('myApp'). config(['$routeProvider' , function($routeProvider ) { $routeProvider .when( '/folder/:name' , {templateUrl : 'partials/folder.html' , controller : FolderCtrl }); }])​
  • 26. Performance ● Browser support: IE 8+, Chrome, FF, Safari, Opera ● Framework size: 503KB ● Application size: 756KB