SlideShare a Scribd company logo
1 of 19
Download to read offline
Tricode BV
De Schutterij 12 -18
3905 PL Veenendaal
The Netherlands
tel: 0318 - 559210
www.tricode.nl
info@tricode.nl
DIVE INTO
ANGULAR JS
AND DIRECTIVES
Andrej Gasteovski
08.04.2015
Agenda
• What is AngularJS?
• Main concepts of AngularJS
• Directives overview
*
What is AngularJS?
AngularJS in general and benefits of using it
What is AngularJS?
“Superheroic JavaScript framework”
- angularjs.org
“Angular is what HTML would have been, had it
been designed for applications.”
- angularjs.org
"AngularJS extends HTML with new
attributes.
AngularJS is perfect for Single Page
Applications (SPAs).
AngularJS is easy to learn.”
- w3schools.com
Web app that fits on a single web page
No need for reloading the whole page
HTML page contains fragments that can be
loaded in the background
Extremely good for responsive sites
Result: Faster, native and more interactive UI
Examples: Voyager, Google Maps, Google
Calendar, Facebook Groups...
Why Single Page Application?
Other AngularJS features
Complete client-side solution
Implements client-side MVC pattern
Uses dependency injection
Implements two-way data binding
No direct DOM manipulation, less code
Unit testable
Support for all major browsers
Supported by Google
Large and fast growing community
Open source, completely free
Main concepts of
AngularJS
Overview of the core features in AngularJS such as data-
binding, scope, controller, directives...
Applications, Modules, Controllers...
AngularJS modules define AngularJS application
var app = angular.module('myApplication', []);
AngularJS controllers control applications
app.controller('myController', function
($scope) {
$scope.title = "Harry Potter";
$scope.author = "J.K. Rowling";
});
Module - container of different parts of the application such as
controllers, services, filter etc.
Scope is the object that links Controller to the View. Controller
should initialize the scope with data that View needs to display.
Controllers are regular JavaScript object.
Data binding in AngularJS
Data binding - automatic synchronization of data
between Model and View.
AngularJS supports Two-Way Data Binding
The template (HTML with
additional resources) is
compiled in the browser. This
step produces a live view.
Any change in the model is
propagated to the view and
any change in the view is
reflected in the model.
angularjs.org
Expressions
Used to bind data to HTML
Written inside double braces: {{ }}
Can contain literals, operators and variables
Similar to JavaScript expressions
<div>
<p>This is an expression: {{ 5 + 10 }}</p>
</div>
<div ng-app="" ng-init="quantity=1;cost=5">
<p>
Total in dollar: {{ quantity * cost }}
</p>
</div>
<div ng-app="" ng-init="firstName='John';
lastName='Doe'">
<p>The name is {{ firstName + " " + lastName }}</p>
</div>
<div ng-app="" ng-init="person={firstName:'John',
lastName:'Doe'}">
<p>The name is {{ person.lastName }}</p>
</div>
*ng-init is a directive that defines initial values for an
AngularJS application
Examples from w3scools.
com
Directives
What are directives?
Attributes used to extend the standard HTML
starting with the ng- prefix.
The main purpose of Directives is to tell Angular to
attach a specified behavior of a DOM element or
even transform a DOM element and his children.
Most used directives:
ng-app, ng-init, ng-model, ng-repeat, ng-bind,
ng-list, ng-value...
ng-app
● Defines the root element of an AngularJS
application
● Used for automatic initialization of the
application when the web page is loaded
● Typically placed in the root element of the page
e.g. <body>
● This directive can include the module that
defines the AngularJS application
<head>
<script>
var app = angular.module('myApplication', []);
</script>
</head>
<body ng-app="myApplication">
<div>
</div>
</body>
ng-controller
● Defines the application controller
● Key aspect to support the MVC pattern
● Controllers contains business logic to decorate
the scope with functions and attributes
● Can be defined in external files
<div ng-app="myApp" ng-controller="bookCTRL">
Title: <input type="text">{{ title }}<br>
Author: <input type="text">{{ author }}<br>
<br>
Full Name: {{fullName()}}
</div>
<script>
var app = angular.module('myApp', []);
app.controller('bookCtrl', function($scope) {
$scope.title = "John";
$scope.author = "Doe";
$scope.fullName = function() {
return $scope.title + " - " + $scope.author;
}
});
</script>
ng-init
● Alternative of using controllers
● Initializes an AngularJS Application data
● Not commonly used
● Use only when aliasing special properties of ng-
repeat
<div ng-app="" ng-init="books=[{title:'Harry Potter',author:'J.K. Rowling'},
{title:'Game of Thrones',author:'G. Margin'}]">
...
</div>
ng-model
● Binds the value of an HTML controls to the
application data
● Provide type validation for application data
● Provide CSS classes for HTML elements
● Bind HTML elements to HTML forms
● Keep the state of the HTML element
<div ng-app="" ng-init="quantity=1;price=5">
Quantity: <input type="number” ng-model="quantity">
Costs: <input type="number" ng-model="price">
Total in dollar: {{ quantity * price }}
</div>
ng-repeat
● Repeats and HTML element for every item in
the collection
● Each element instance has its own scope and
the given loop variable is set to the current
collection item
<div ng-app="" ng-init="names=[
{name:'Jani',country:'Norway'},
{name:'Hege',country:'Sweden'},
{name:'Kai',country:'Denmark'}]">
<ul>
<li ng-repeat="x in names">
{{ x.name + ', ' + x.country }}
</li>
</ul>
</div>
Looping with objects:
● Jani, Norway
● Hege, Sweden
● Kai, Denmark
Examples from w3scools.
com
Summary
AngularJS is a powerful JavaScript framework for
client-side applications based on the standard MVC
pattern. The most powerful part of Angular are its
directives that allows extension of the standard
HTML. Applications built with AngularJS are easy
for testing, maintainable, contain reusable
components and well architectured.
More information about AngularJS:
w3school AngularJS tutorial
Official AngularJS API Docs
Interactive tutorial about AngularJS
Follow us:
tricode.nl
facebook.com/tricode
linkedin.com/company/tricode
slideshare.net/tricode
twitter.com/tricode

More Related Content

What's hot

What's hot (20)

Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular js
 
Why angular js Framework
Why angular js Framework Why angular js Framework
Why angular js Framework
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
Angular js
Angular jsAngular js
Angular js
 
AngularJS Basic Training
AngularJS Basic TrainingAngularJS Basic Training
AngularJS Basic Training
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
AngularJS Best Practices
AngularJS Best PracticesAngularJS Best Practices
AngularJS Best Practices
 
AngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
AngularJs Superheroic JavaScript MVW Framework Services by Miracle StudiosAngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
AngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
 
Angular js
Angular jsAngular js
Angular js
 
Mini-Training: AngularJS
Mini-Training: AngularJSMini-Training: AngularJS
Mini-Training: AngularJS
 
AngularJS
AngularJSAngularJS
AngularJS
 
AngularJS in 60ish Minutes
AngularJS in 60ish MinutesAngularJS in 60ish Minutes
AngularJS in 60ish Minutes
 
Understanding angular js $rootscope and $scope
Understanding angular js $rootscope and $scopeUnderstanding angular js $rootscope and $scope
Understanding angular js $rootscope and $scope
 
intro to Angular js
intro to Angular jsintro to Angular js
intro to Angular js
 
Step by Step - AngularJS
Step by Step - AngularJSStep by Step - AngularJS
Step by Step - AngularJS
 
Shaping up with angular JS
Shaping up with angular JSShaping up with angular JS
Shaping up with angular JS
 
Built in filters
Built in filtersBuilt in filters
Built in filters
 
Directives
DirectivesDirectives
Directives
 
Intro to AngularJs
Intro to AngularJsIntro to AngularJs
Intro to AngularJs
 
22 j query1
22 j query122 j query1
22 j query1
 

Viewers also liked

Angular js presentation at Datacom
Angular js presentation at DatacomAngular js presentation at Datacom
Angular js presentation at Datacom
David Xi Peng Yang
 

Viewers also liked (11)

AngularJs
AngularJsAngularJs
AngularJs
 
AngularJS - TechTalk 3/2/2014
AngularJS - TechTalk 3/2/2014AngularJS - TechTalk 3/2/2014
AngularJS - TechTalk 3/2/2014
 
Intro to AngularJS
Intro to AngularJS Intro to AngularJS
Intro to AngularJS
 
Angularjs 131211063348-phpapp01
Angularjs 131211063348-phpapp01Angularjs 131211063348-phpapp01
Angularjs 131211063348-phpapp01
 
AngularJS vs jQuery
AngularJS vs jQueryAngularJS vs jQuery
AngularJS vs jQuery
 
Angular js presentation at Datacom
Angular js presentation at DatacomAngular js presentation at Datacom
Angular js presentation at Datacom
 
Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...
Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...
Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...
 
Introduction to AngularJs
Introduction to AngularJsIntroduction to AngularJs
Introduction to AngularJs
 
AngularJS : Superheroic JavaScript MVW Framework
AngularJS : Superheroic JavaScript MVW FrameworkAngularJS : Superheroic JavaScript MVW Framework
AngularJS : Superheroic JavaScript MVW Framework
 
AngularJS
AngularJSAngularJS
AngularJS
 
Single Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJSSingle Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJS
 

Similar to Dive into AngularJS and directives

Similar to Dive into AngularJS and directives (20)

AngularJs
AngularJsAngularJs
AngularJs
 
Workshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte IWorkshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte I
 
Angular js
Angular jsAngular js
Angular js
 
Introduction to AngularJS By Bharat Makwana
Introduction to AngularJS By Bharat MakwanaIntroduction to AngularJS By Bharat Makwana
Introduction to AngularJS By Bharat Makwana
 
Angular.js опыт использования, проблемы и решения
Angular.js опыт использования, проблемы и решенияAngular.js опыт использования, проблемы и решения
Angular.js опыт использования, проблемы и решения
 
AngularJS By Vipin
AngularJS By VipinAngularJS By Vipin
AngularJS By Vipin
 
Angular js
Angular jsAngular js
Angular js
 
Angular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseAngular Js Get Started - Complete Course
Angular Js Get Started - Complete Course
 
AngularJS Workshop
AngularJS WorkshopAngularJS Workshop
AngularJS Workshop
 
Angular js slides
Angular js slidesAngular js slides
Angular js slides
 
Learning AngularJS - Complete coverage of AngularJS features and concepts
Learning AngularJS  - Complete coverage of AngularJS features and conceptsLearning AngularJS  - Complete coverage of AngularJS features and concepts
Learning AngularJS - Complete coverage of AngularJS features and concepts
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get started
 
Introduction of angular js
Introduction of angular jsIntroduction of angular js
Introduction of angular js
 
The Basics Angular JS
The Basics Angular JS The Basics Angular JS
The Basics Angular JS
 
AngularJS Mobile Warsaw 20-10-2014
AngularJS Mobile Warsaw 20-10-2014AngularJS Mobile Warsaw 20-10-2014
AngularJS Mobile Warsaw 20-10-2014
 
Training On Angular Js
Training On Angular JsTraining On Angular Js
Training On Angular Js
 
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSAngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
 
One Weekend With AngularJS
One Weekend With AngularJSOne Weekend With AngularJS
One Weekend With AngularJS
 
Angular js
Angular jsAngular js
Angular js
 
Basics of AngularJS
Basics of AngularJSBasics of AngularJS
Basics of AngularJS
 

More from Tricode (part of Dept)

More from Tricode (part of Dept) (20)

The Top Benefits of Magnolia CMS’s Inspirational Open Suite Ideology
The Top Benefits of Magnolia CMS’s Inspirational Open Suite IdeologyThe Top Benefits of Magnolia CMS’s Inspirational Open Suite Ideology
The Top Benefits of Magnolia CMS’s Inspirational Open Suite Ideology
 
Agile QA 2017: A New Hope
Agile QA 2017: A New HopeAgile QA 2017: A New Hope
Agile QA 2017: A New Hope
 
Mobile Sensor Networks based on Smartphone devices and Web Services
Mobile Sensor Networks based on Smartphone devices and Web ServicesMobile Sensor Networks based on Smartphone devices and Web Services
Mobile Sensor Networks based on Smartphone devices and Web Services
 
Keeping Your Clients Happy and Your Management Even Happier
Keeping Your Clients Happy and Your Management Even Happier Keeping Your Clients Happy and Your Management Even Happier
Keeping Your Clients Happy and Your Management Even Happier
 
Intro to JHipster
Intro to JHipster Intro to JHipster
Intro to JHipster
 
Porn, the leading influencer of Technology
Porn, the leading influencer of Technology Porn, the leading influencer of Technology
Porn, the leading influencer of Technology
 
De 4 belangrijkste risicofactoren van het nearshoring proces
De 4 belangrijkste risicofactoren van het nearshoring procesDe 4 belangrijkste risicofactoren van het nearshoring proces
De 4 belangrijkste risicofactoren van het nearshoring proces
 
Internet Addiction (Social Media Edition)
Internet Addiction (Social Media Edition)Internet Addiction (Social Media Edition)
Internet Addiction (Social Media Edition)
 
Kids Can Code - an interactive IT workshop
Kids Can Code - an interactive IT workshopKids Can Code - an interactive IT workshop
Kids Can Code - an interactive IT workshop
 
RESTful API - Best Practices
RESTful API - Best PracticesRESTful API - Best Practices
RESTful API - Best Practices
 
Deep Learning - STM 6
Deep Learning - STM 6Deep Learning - STM 6
Deep Learning - STM 6
 
How Technology is Affecting Society - STM 6
How Technology is Affecting Society - STM 6How Technology is Affecting Society - STM 6
How Technology is Affecting Society - STM 6
 
Monolithic to Microservices Architecture - STM 6
Monolithic to Microservices Architecture - STM 6Monolithic to Microservices Architecture - STM 6
Monolithic to Microservices Architecture - STM 6
 
Customers speak on Magnolia CMS
Customers speak on Magnolia CMSCustomers speak on Magnolia CMS
Customers speak on Magnolia CMS
 
Quality Nearshoring met Tricode
Quality Nearshoring met TricodeQuality Nearshoring met Tricode
Quality Nearshoring met Tricode
 
AEM Digital Assets Management - What's new in 6.2?
AEM Digital Assets Management - What's new in 6.2?AEM Digital Assets Management - What's new in 6.2?
AEM Digital Assets Management - What's new in 6.2?
 
10 nearshoring it trends om in 2016 te volgen
10 nearshoring it trends om in 2016 te volgen 10 nearshoring it trends om in 2016 te volgen
10 nearshoring it trends om in 2016 te volgen
 
Tricode & Magnolia
Tricode & MagnoliaTricode & Magnolia
Tricode & Magnolia
 
Why you should use Adobe Experience Manager Mobile
Why you should use Adobe Experience Manager Mobile Why you should use Adobe Experience Manager Mobile
Why you should use Adobe Experience Manager Mobile
 
Introducing: Tricode's Software Factory
Introducing: Tricode's Software FactoryIntroducing: Tricode's Software Factory
Introducing: Tricode's Software Factory
 

Recently uploaded

Recently uploaded (20)

Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 

Dive into AngularJS and directives

  • 1. Tricode BV De Schutterij 12 -18 3905 PL Veenendaal The Netherlands tel: 0318 - 559210 www.tricode.nl info@tricode.nl DIVE INTO ANGULAR JS AND DIRECTIVES Andrej Gasteovski 08.04.2015
  • 2. Agenda • What is AngularJS? • Main concepts of AngularJS • Directives overview *
  • 3. What is AngularJS? AngularJS in general and benefits of using it
  • 4. What is AngularJS? “Superheroic JavaScript framework” - angularjs.org “Angular is what HTML would have been, had it been designed for applications.” - angularjs.org "AngularJS extends HTML with new attributes. AngularJS is perfect for Single Page Applications (SPAs). AngularJS is easy to learn.” - w3schools.com
  • 5. Web app that fits on a single web page No need for reloading the whole page HTML page contains fragments that can be loaded in the background Extremely good for responsive sites Result: Faster, native and more interactive UI Examples: Voyager, Google Maps, Google Calendar, Facebook Groups... Why Single Page Application?
  • 6. Other AngularJS features Complete client-side solution Implements client-side MVC pattern Uses dependency injection Implements two-way data binding No direct DOM manipulation, less code Unit testable Support for all major browsers Supported by Google Large and fast growing community Open source, completely free
  • 7. Main concepts of AngularJS Overview of the core features in AngularJS such as data- binding, scope, controller, directives...
  • 8. Applications, Modules, Controllers... AngularJS modules define AngularJS application var app = angular.module('myApplication', []); AngularJS controllers control applications app.controller('myController', function ($scope) { $scope.title = "Harry Potter"; $scope.author = "J.K. Rowling"; }); Module - container of different parts of the application such as controllers, services, filter etc. Scope is the object that links Controller to the View. Controller should initialize the scope with data that View needs to display. Controllers are regular JavaScript object.
  • 9. Data binding in AngularJS Data binding - automatic synchronization of data between Model and View. AngularJS supports Two-Way Data Binding The template (HTML with additional resources) is compiled in the browser. This step produces a live view. Any change in the model is propagated to the view and any change in the view is reflected in the model. angularjs.org
  • 10. Expressions Used to bind data to HTML Written inside double braces: {{ }} Can contain literals, operators and variables Similar to JavaScript expressions <div> <p>This is an expression: {{ 5 + 10 }}</p> </div> <div ng-app="" ng-init="quantity=1;cost=5"> <p> Total in dollar: {{ quantity * cost }} </p> </div> <div ng-app="" ng-init="firstName='John'; lastName='Doe'"> <p>The name is {{ firstName + " " + lastName }}</p> </div> <div ng-app="" ng-init="person={firstName:'John', lastName:'Doe'}"> <p>The name is {{ person.lastName }}</p> </div> *ng-init is a directive that defines initial values for an AngularJS application Examples from w3scools. com
  • 12. What are directives? Attributes used to extend the standard HTML starting with the ng- prefix. The main purpose of Directives is to tell Angular to attach a specified behavior of a DOM element or even transform a DOM element and his children. Most used directives: ng-app, ng-init, ng-model, ng-repeat, ng-bind, ng-list, ng-value...
  • 13. ng-app ● Defines the root element of an AngularJS application ● Used for automatic initialization of the application when the web page is loaded ● Typically placed in the root element of the page e.g. <body> ● This directive can include the module that defines the AngularJS application <head> <script> var app = angular.module('myApplication', []); </script> </head> <body ng-app="myApplication"> <div> </div> </body>
  • 14. ng-controller ● Defines the application controller ● Key aspect to support the MVC pattern ● Controllers contains business logic to decorate the scope with functions and attributes ● Can be defined in external files <div ng-app="myApp" ng-controller="bookCTRL"> Title: <input type="text">{{ title }}<br> Author: <input type="text">{{ author }}<br> <br> Full Name: {{fullName()}} </div> <script> var app = angular.module('myApp', []); app.controller('bookCtrl', function($scope) { $scope.title = "John"; $scope.author = "Doe"; $scope.fullName = function() { return $scope.title + " - " + $scope.author; } }); </script>
  • 15. ng-init ● Alternative of using controllers ● Initializes an AngularJS Application data ● Not commonly used ● Use only when aliasing special properties of ng- repeat <div ng-app="" ng-init="books=[{title:'Harry Potter',author:'J.K. Rowling'}, {title:'Game of Thrones',author:'G. Margin'}]"> ... </div>
  • 16. ng-model ● Binds the value of an HTML controls to the application data ● Provide type validation for application data ● Provide CSS classes for HTML elements ● Bind HTML elements to HTML forms ● Keep the state of the HTML element <div ng-app="" ng-init="quantity=1;price=5"> Quantity: <input type="number” ng-model="quantity"> Costs: <input type="number" ng-model="price"> Total in dollar: {{ quantity * price }} </div>
  • 17. ng-repeat ● Repeats and HTML element for every item in the collection ● Each element instance has its own scope and the given loop variable is set to the current collection item <div ng-app="" ng-init="names=[ {name:'Jani',country:'Norway'}, {name:'Hege',country:'Sweden'}, {name:'Kai',country:'Denmark'}]"> <ul> <li ng-repeat="x in names"> {{ x.name + ', ' + x.country }} </li> </ul> </div> Looping with objects: ● Jani, Norway ● Hege, Sweden ● Kai, Denmark Examples from w3scools. com
  • 18. Summary AngularJS is a powerful JavaScript framework for client-side applications based on the standard MVC pattern. The most powerful part of Angular are its directives that allows extension of the standard HTML. Applications built with AngularJS are easy for testing, maintainable, contain reusable components and well architectured. More information about AngularJS: w3school AngularJS tutorial Official AngularJS API Docs Interactive tutorial about AngularJS