SlideShare une entreprise Scribd logo
1  sur  11
Télécharger pour lire hors ligne
AngularJS
What Is AngularJS ?
client-side technology, written entirely in JavaScript. It works with the
long-established technologies of the web (HTML, CSS, and JavaScript) to make the
development of web apps easier and faster than ever before.
It is a framework that is primarily used to build single-page web applications
(refer this : http://en.wikipedia.org/wiki/Single-page_application).
The AngularJS team describes it as a "structural framework for dynamic web apps."
How Is It different?
In other JavaScript frameworks, we are forced to extend from custom JavaScript
objects and manipulate the DOM from the outside in. For instance, using jQuery, to
add a button in the DOM, we’ll have to know where we’re putting the element and
insert it in the appropriate place:
var btn = $("<button>Hi</button>");
btn.on('click', function(evt) {
console.log("Clicked button")
});
$("#checkoutHolder").append(btn);
Although this process is not complex, it requires the developer to have knowledge
of the entire DOM
and force our complex logic inside JavaScript code to manipulate a foreign DOM.
AngularJS, on the other hand, augments HTML to give it native
Model-View-Controller (MVC) capabilities. This choice, as it turns out, makes
building impressive and expressive client-side applications quick and enjoyable.
License:
The AngularJS source code is made freely available on
Github(https://github.com/angular/angular.js) under the MIT license.
Your First AngularJS Web Application :
Let's Do "Hello World" :)
<!DOCTYPE html>
<html ng-app>
<head>
<title>Simple app</title>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js"></script>
</head>
<body>
<input ng-model="name" type="text" placeholder="Your name">
<h1>Hello {{ name }}</h1>
</body>
</html>
Try here: http://jsfiddle.net/asP3X/
Introducing Data Binding in AngularJS :
In classic web frameworks,such as Rails,the controller combines data from models
and mashes them together with templates to deliver a view to the user. This
combination produces a single-way view. Without building any custom JavaScript
components, the view will only reflect the data the model exposes at the time of
the view rendering. At the time of this writing, there are several JavaScript
frameworks that promise automatic data binding of the view and the model.
AngularJS takes a different approach. Instead of merging data into a template and
replacing a DOM element, AngularJS creates live templates as a view. Individual
components of the views are dynamically interpolated live. This feature is arguably
one of the most important in AngularJS and allows us to write the "hello world" app
we just wrote in only 10 lines of code without a single line of JavaScript.
This feature works by simply including angular.js in our HTML and explicitly setting
the ng-app attribute on an element in the DOM. The ng-app attribute declares that
everything inside of it belongs to this Angular app; that’s how we can nest an
Angular app inside of a web app. The only components that will be affected by
Angular are the DOM elements that we declare inside of the one with the "ng-app"
attribute.
To declare our above example inside of a controller, we’ll change the HTML to look
like:
<div ng-controller='MyController'>
<input ng-model="name" type="text" placeholder="Your name">
<h1>Hello {{ name }}, <br />Time is : {{clock}}</h1>
</div>
In this example, we’ll create a clock that will tick every second (as clocks usually
do) and change the
data on the clock variable:
Controller:
function MyController($scope) {
var updateClock = function() {
$scope.clock =new Date();
};
setInterval( function() {
$scope.$apply(updateClock);
},1000);
updateClock();
};
Live Demo : http://jsfiddle.net/asP3X/1/
Modules :
In JavaScript, placing functional code in the global namespace is rarely a good idea.
It can cause collisions that are tough to debug and cost us precious development
time.
When looking at data binding in the previous chapter, we wrote our controllers in
the global
namespace by defining a single function:
function MyController($scope) {
var updateClock = function() {
$scope.clock = new Date();
};
setInterval(function() {
$scope.$apply(updateClock);
},1000);
updateClock();
}
Lets talk about how to write efficient, production-ready controllers by encapsulating
our functionality in a single core unit called a module.
In Angular, a module is the main way to define an AngularJS app. The module of an
app is where we’ll contain all of our application code. An app can contain several
modules, each one containing
code that pertains to specific functionality.
Using modules gives us a lot of advantages, such as:
• Keeping our global namespace clean
• Making tests easier to write and keeping them clean so as to more easily target
isolated functionality
• Making it easy to share code between applications
• Allowing our app to load different parts of the code in any order.
The Angular module API allows us to declare a module using the
angular.module(string, [arrayofstrings]) API method.
Properties
Angular modules have properties that we can use to inspect the module.
name(string)
The name property on the modules gives us the name of the module as a string.
requires(array of strings)
The requires property contains a list of modules (as strings) that the
injector loads before the module itself is loaded.
Scopes ($scope)
Scopes are a core fundamental of any Angular app. They are used all over the
framework, so it’s important to know them and how they work.
The scopes of the application refer to the application model. Scopes are the
execution context for expressions. The $scope object is where we define the
business functinality of the application, the methods in our controllers, and
properties in the views.
Scopes serve as the glue between the controller and the view. Just before our app
renders the view to the user, the view template links to the scope, and the app sets
up the DOM to notify Angular for property changes.
Scopes are the source of truth for the application state. Because of this live binding,
we can rely on the $scope to update immediately when the view modifies it, and we
can rely on the view to update when the $scope changes.
$scopes in AngularJS are arranged in a hierarchical structure that mimics the DOM
and thus are nestable: We can reference properties on parent $scopes.
What Can Scopes Do?
Scopes have the following basic functions:
• They provide observers to watch for model changes
•They provide the ability to propagate model changes through the application as
well as outside the system to other components
•They can be nested such that they can isolate functionality and model properties
•They provide an execution environment in which expressions are evaluated.
The majority of the work we’ll do in developing our Angular app is building out the
functionality of a scope.
Filters
In AngularJS, a filter provides a way to format the data we display to the user.
Angular gives us
several built-in filters as well as an easy way to create our own.
We invoke filters in our HTML with the "|"
(pipe) character inside the template binding characters
{{}}. For instance, let’s say we want to capitalize our string. We can either change
all the characters
in a string to be capitalized, or we can use a filter.
{{ name | uppercase }}
We can also use filters from within JavaScript by using the
$filter service. For instance, to use the lowercase JavaScript filter:
app.controller('DemoController', ['$scope','$filter',function($scope, $filter) {
$scope.name =$filter('lowercase')('Ari');
}]);
currency
The currency filter formats a number as currency. In other words, 123 as currency
looks like: {{ 123 | currency }}. can use like currency :'$'
Currency gives us the option of displaying a currency symbol or identifier.
date
The date filter allows us to format a date based upon a requested format style. The
date formatter provides us several built-in options. If no date format is passed,
then it defaults to showing mediumDate (as you can see below).
{{ today | date:'medium' }} <!--Aug 09, 2013 12:09:02 PM-->
{{ today | date:'short' }} <!--8/9/13 12:09 PM-->
{{ today | date:'fullDate' }} <!--Thursday, August 09, 2013-->
{{ today | date:'longDate' }} <!--August 09, 2013-->
{{ today | date:'mediumDate' }} <!--Aug 09, 2013-->
{{ today | date:'shortDate' }} <!--8/9/13-->
{{ today | date:'mediumTime' }} <!--12:09:02 PM-->
{{ today | date:'shortTime' }} <!--12:09 PM-->
Year Formatting
Four-digit year: {{ today | date:'yyyy' }} <!--2013-->
Two-digit padded year: {{ today | date:'yy' }} <!--13-->
One-digit year: {{ today | date:'y' }} <!--2013-->
And Many More.
The filter filter selects a subset of items from an array of items and returns a new
array. This filter is generally used as a way to filter out items for display. For
instance, when using client-side searching, we can filter out items from an array
immediately.
The filter method takes a string, object, or function that it will run to select or reject
array elements. If the first parameter passed in is a:
Live Demo : http://jsfiddle.net/asP3X/3/
Introduction to Directives :
Any attribute that starts with "ng-" is a directive.
Use it as "ng-" when usinh in views.
ex:
• ngRepeat (enter, leave and move animations) use it as ng-repeat
• ngInclude (enter and leave animations) use it as ng-include
• ngView (enter and leave animations) use it as ng-view
• ngIf (enter and leave animations) use it as ng-if
• ngSwitch (enter and leave animations) use it as ng-switch
• ngClass (addClass and removeClass animations) use it as ng-class
• ngShow and ngHide (addClass and removeClass animations for
.ng-hide).use it as ng-show, ng-hide.
Our First Directive
We use directives to extend the html5.
<my-directive></my-directive>
Directive:
angular.module('myApp', [])
.directive('myDirective',function() {
return{
restrict:'E',
template:'<a href="http://google.com">Click me to go to Google</a>'
}
});
So here is the result:
And when you see the source :
Table 6-2. Directive definition options
restrict : Declare how directive can be used in a template as an element, attribute,
class, comment, or any combination.
priority : Set the order of execution in the template relative to other directives on
the element.
template : Specify an inline template as a string. Not used if you’re specifying your
template as a URL.
templateUrl : Specify the template to be loaded by URL. This is not used if you’ve
specified an inline template as a string.
replace : If true, replace the current element. If false or unspecified, append this
directive to the current element.
transclude : Lets you move the original children of a directive to a location inside
the new template.
scope : Create a new scope for this directive rather than inheriting the parent
scope.
controller : Create a controller which publishes an API for communicating across
directives.
require : Require that another directive be present for this directive to function
correctly.
link : Programmatically modify resulting DOM element instances, add event
listeners, and set up data binding.
compile : Programmatically modify the DOM template for features across copies of
a directive, as when used in ng-repeat. Your compile function can also return link
functions to modify the resulting element instances.
For more on AngularJs, Explore the site http://angularjs.org/. and can find many
tutorials and blogs.
Have a support in stackoverflow:
http://stackoverflow.com/questions/tagged/angularjs

Contenu connexe

Tendances

AngularJS best-practices
AngularJS best-practicesAngularJS best-practices
AngularJS best-practicesHenry Tao
 
Angular JS - Introduction
Angular JS - IntroductionAngular JS - Introduction
Angular JS - IntroductionSagar Acharya
 
AngularJS application architecture
AngularJS application architectureAngularJS application architecture
AngularJS application architectureGabriele Falace
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular jsAayush Shrestha
 
Why angular js Framework
Why angular js Framework Why angular js Framework
Why angular js Framework Sakthi Bro
 
AngularJS with RequireJS
AngularJS with RequireJSAngularJS with RequireJS
AngularJS with RequireJSJohannes Weber
 
Angularjs - lazy loading techniques
Angularjs - lazy loading techniques Angularjs - lazy loading techniques
Angularjs - lazy loading techniques Nir Kaufman
 
Angular js tutorial slides
Angular js tutorial slidesAngular js tutorial slides
Angular js tutorial slidessamhelman
 
AngularJS Basics and Best Practices - CC FE &UX
AngularJS Basics and Best Practices - CC FE &UXAngularJS Basics and Best Practices - CC FE &UX
AngularJS Basics and Best Practices - CC FE &UXJWORKS powered by Ordina
 
AngularJS - Architecture decisions in a large project 
AngularJS - Architecture decisionsin a large project AngularJS - Architecture decisionsin a large project 
AngularJS - Architecture decisions in a large project Elad Hirsch
 
AngularJS Beginners Workshop
AngularJS Beginners WorkshopAngularJS Beginners Workshop
AngularJS Beginners WorkshopSathish VJ
 
Step by Step - AngularJS
Step by Step - AngularJSStep by Step - AngularJS
Step by Step - AngularJSInfragistics
 
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 startedStéphane Bégaudeau
 
AngularJS One Day Workshop
AngularJS One Day WorkshopAngularJS One Day Workshop
AngularJS One Day WorkshopShyam Seshadri
 
Gettings started with the superheroic JavaScript library AngularJS
Gettings started with the superheroic JavaScript library AngularJSGettings started with the superheroic JavaScript library AngularJS
Gettings started with the superheroic JavaScript library AngularJSArmin Vieweg
 
Front end development with Angular JS
Front end development with Angular JSFront end development with Angular JS
Front end development with Angular JSBipin
 

Tendances (20)

Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
 
AngularJS best-practices
AngularJS best-practicesAngularJS best-practices
AngularJS best-practices
 
Angular JS - Introduction
Angular JS - IntroductionAngular JS - Introduction
Angular JS - Introduction
 
AngularJS application architecture
AngularJS application architectureAngularJS application architecture
AngularJS application architecture
 
Angular js
Angular jsAngular js
Angular js
 
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
 
Angular js
Angular jsAngular js
Angular js
 
AngularJS with RequireJS
AngularJS with RequireJSAngularJS with RequireJS
AngularJS with RequireJS
 
Angularjs - lazy loading techniques
Angularjs - lazy loading techniques Angularjs - lazy loading techniques
Angularjs - lazy loading techniques
 
Angular js tutorial slides
Angular js tutorial slidesAngular js tutorial slides
Angular js tutorial slides
 
AngularJS Basics and Best Practices - CC FE &UX
AngularJS Basics and Best Practices - CC FE &UXAngularJS Basics and Best Practices - CC FE &UX
AngularJS Basics and Best Practices - CC FE &UX
 
AngularJS - Architecture decisions in a large project 
AngularJS - Architecture decisionsin a large project AngularJS - Architecture decisionsin a large project 
AngularJS - Architecture decisions in a large project 
 
AngularJS Beginners Workshop
AngularJS Beginners WorkshopAngularJS Beginners Workshop
AngularJS Beginners Workshop
 
Step by Step - AngularJS
Step by Step - AngularJSStep by Step - AngularJS
Step by Step - AngularJS
 
Angular js
Angular jsAngular js
Angular js
 
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
 
AngularJS One Day Workshop
AngularJS One Day WorkshopAngularJS One Day Workshop
AngularJS One Day Workshop
 
Gettings started with the superheroic JavaScript library AngularJS
Gettings started with the superheroic JavaScript library AngularJSGettings started with the superheroic JavaScript library AngularJS
Gettings started with the superheroic JavaScript library AngularJS
 
Front end development with Angular JS
Front end development with Angular JSFront end development with Angular JS
Front end development with Angular JS
 

Similaire à AngularJS Basics

Angular workshop - Full Development Guide
Angular workshop - Full Development GuideAngular workshop - Full Development Guide
Angular workshop - Full Development GuideNitin Giri
 
One Weekend With AngularJS
One Weekend With AngularJSOne Weekend With AngularJS
One Weekend With AngularJSYashobanta Bai
 
Intoduction to Angularjs
Intoduction to AngularjsIntoduction to Angularjs
Intoduction to AngularjsGaurav Agrawal
 
Angular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseAngular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseEPAM Systems
 
The Basics Angular JS
The Basics Angular JS The Basics Angular JS
The Basics Angular JS OrisysIndia
 
introduction to Angularjs basics
introduction to Angularjs basicsintroduction to Angularjs basics
introduction to Angularjs basicsRavindra K
 
Angular Project Report
 Angular Project Report Angular Project Report
Angular Project ReportKodexhub
 
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 StudiosLearnimtactics
 
AngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPIAngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPIEric Wise
 
Angular Interview Questions-PDF.pdf
Angular Interview Questions-PDF.pdfAngular Interview Questions-PDF.pdf
Angular Interview Questions-PDF.pdfJohnLeo57
 
Angular js 1.3 presentation for fed nov 2014
Angular js 1.3 presentation for fed   nov 2014Angular js 1.3 presentation for fed   nov 2014
Angular js 1.3 presentation for fed nov 2014Sarah Hudson
 
Angular tutorial
Angular tutorialAngular tutorial
Angular tutorialRohit Gupta
 
Angularjs 131211063348-phpapp01
Angularjs 131211063348-phpapp01Angularjs 131211063348-phpapp01
Angularjs 131211063348-phpapp01Arunangsu Sahu
 

Similaire à AngularJS Basics (20)

Angular workshop - Full Development Guide
Angular workshop - Full Development GuideAngular workshop - Full Development Guide
Angular workshop - Full Development Guide
 
One Weekend With AngularJS
One Weekend With AngularJSOne Weekend With AngularJS
One Weekend With AngularJS
 
Intoduction to Angularjs
Intoduction to AngularjsIntoduction to Angularjs
Intoduction to Angularjs
 
Training On Angular Js
Training On Angular JsTraining On Angular Js
Training On Angular Js
 
Angular js
Angular jsAngular js
Angular js
 
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
 
The Basics Angular JS
The Basics Angular JS The Basics Angular JS
The Basics Angular JS
 
introduction to Angularjs basics
introduction to Angularjs basicsintroduction to Angularjs basics
introduction to Angularjs basics
 
Angular Project Report
 Angular Project Report Angular Project Report
Angular Project Report
 
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
 
AngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPIAngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPI
 
Angular js
Angular jsAngular js
Angular js
 
AngularJS in practice
AngularJS in practiceAngularJS in practice
AngularJS in practice
 
Angular Interview Questions-PDF.pdf
Angular Interview Questions-PDF.pdfAngular Interview Questions-PDF.pdf
Angular Interview Questions-PDF.pdf
 
Angular js 1.3 presentation for fed nov 2014
Angular js 1.3 presentation for fed   nov 2014Angular js 1.3 presentation for fed   nov 2014
Angular js 1.3 presentation for fed nov 2014
 
Angular js
Angular jsAngular js
Angular js
 
Angular tutorial
Angular tutorialAngular tutorial
Angular tutorial
 
AngularJs
AngularJsAngularJs
AngularJs
 
Angularjs 131211063348-phpapp01
Angularjs 131211063348-phpapp01Angularjs 131211063348-phpapp01
Angularjs 131211063348-phpapp01
 

Dernier

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
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 productivityPrincipled Technologies
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
The Evolution of Money: Digital Transformation and CBDCs in Central Banking
The Evolution of Money: Digital Transformation and CBDCs in Central BankingThe Evolution of Money: Digital Transformation and CBDCs in Central Banking
The Evolution of Money: Digital Transformation and CBDCs in Central BankingSelcen Ozturkcan
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 

Dernier (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
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
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
The Evolution of Money: Digital Transformation and CBDCs in Central Banking
The Evolution of Money: Digital Transformation and CBDCs in Central BankingThe Evolution of Money: Digital Transformation and CBDCs in Central Banking
The Evolution of Money: Digital Transformation and CBDCs in Central Banking
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 

AngularJS Basics

  • 1. AngularJS What Is AngularJS ? client-side technology, written entirely in JavaScript. It works with the long-established technologies of the web (HTML, CSS, and JavaScript) to make the development of web apps easier and faster than ever before. It is a framework that is primarily used to build single-page web applications (refer this : http://en.wikipedia.org/wiki/Single-page_application). The AngularJS team describes it as a "structural framework for dynamic web apps." How Is It different? In other JavaScript frameworks, we are forced to extend from custom JavaScript objects and manipulate the DOM from the outside in. For instance, using jQuery, to add a button in the DOM, we’ll have to know where we’re putting the element and insert it in the appropriate place: var btn = $("<button>Hi</button>"); btn.on('click', function(evt) { console.log("Clicked button") }); $("#checkoutHolder").append(btn); Although this process is not complex, it requires the developer to have knowledge of the entire DOM and force our complex logic inside JavaScript code to manipulate a foreign DOM. AngularJS, on the other hand, augments HTML to give it native Model-View-Controller (MVC) capabilities. This choice, as it turns out, makes building impressive and expressive client-side applications quick and enjoyable.
  • 2. License: The AngularJS source code is made freely available on Github(https://github.com/angular/angular.js) under the MIT license. Your First AngularJS Web Application : Let's Do "Hello World" :) <!DOCTYPE html> <html ng-app> <head> <title>Simple app</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js"></script> </head> <body> <input ng-model="name" type="text" placeholder="Your name"> <h1>Hello {{ name }}</h1> </body> </html> Try here: http://jsfiddle.net/asP3X/ Introducing Data Binding in AngularJS : In classic web frameworks,such as Rails,the controller combines data from models and mashes them together with templates to deliver a view to the user. This combination produces a single-way view. Without building any custom JavaScript components, the view will only reflect the data the model exposes at the time of
  • 3. the view rendering. At the time of this writing, there are several JavaScript frameworks that promise automatic data binding of the view and the model. AngularJS takes a different approach. Instead of merging data into a template and replacing a DOM element, AngularJS creates live templates as a view. Individual components of the views are dynamically interpolated live. This feature is arguably one of the most important in AngularJS and allows us to write the "hello world" app we just wrote in only 10 lines of code without a single line of JavaScript. This feature works by simply including angular.js in our HTML and explicitly setting the ng-app attribute on an element in the DOM. The ng-app attribute declares that everything inside of it belongs to this Angular app; that’s how we can nest an Angular app inside of a web app. The only components that will be affected by Angular are the DOM elements that we declare inside of the one with the "ng-app" attribute. To declare our above example inside of a controller, we’ll change the HTML to look like: <div ng-controller='MyController'> <input ng-model="name" type="text" placeholder="Your name"> <h1>Hello {{ name }}, <br />Time is : {{clock}}</h1> </div> In this example, we’ll create a clock that will tick every second (as clocks usually do) and change the data on the clock variable: Controller: function MyController($scope) { var updateClock = function() { $scope.clock =new Date(); }; setInterval( function() { $scope.$apply(updateClock);
  • 4. },1000); updateClock(); }; Live Demo : http://jsfiddle.net/asP3X/1/ Modules : In JavaScript, placing functional code in the global namespace is rarely a good idea. It can cause collisions that are tough to debug and cost us precious development time. When looking at data binding in the previous chapter, we wrote our controllers in the global namespace by defining a single function: function MyController($scope) { var updateClock = function() { $scope.clock = new Date(); }; setInterval(function() { $scope.$apply(updateClock); },1000); updateClock(); } Lets talk about how to write efficient, production-ready controllers by encapsulating our functionality in a single core unit called a module. In Angular, a module is the main way to define an AngularJS app. The module of an app is where we’ll contain all of our application code. An app can contain several modules, each one containing
  • 5. code that pertains to specific functionality. Using modules gives us a lot of advantages, such as: • Keeping our global namespace clean • Making tests easier to write and keeping them clean so as to more easily target isolated functionality • Making it easy to share code between applications • Allowing our app to load different parts of the code in any order. The Angular module API allows us to declare a module using the angular.module(string, [arrayofstrings]) API method. Properties Angular modules have properties that we can use to inspect the module. name(string) The name property on the modules gives us the name of the module as a string. requires(array of strings) The requires property contains a list of modules (as strings) that the injector loads before the module itself is loaded. Scopes ($scope) Scopes are a core fundamental of any Angular app. They are used all over the framework, so it’s important to know them and how they work. The scopes of the application refer to the application model. Scopes are the execution context for expressions. The $scope object is where we define the business functinality of the application, the methods in our controllers, and properties in the views. Scopes serve as the glue between the controller and the view. Just before our app renders the view to the user, the view template links to the scope, and the app sets up the DOM to notify Angular for property changes.
  • 6. Scopes are the source of truth for the application state. Because of this live binding, we can rely on the $scope to update immediately when the view modifies it, and we can rely on the view to update when the $scope changes. $scopes in AngularJS are arranged in a hierarchical structure that mimics the DOM and thus are nestable: We can reference properties on parent $scopes. What Can Scopes Do? Scopes have the following basic functions: • They provide observers to watch for model changes •They provide the ability to propagate model changes through the application as well as outside the system to other components •They can be nested such that they can isolate functionality and model properties •They provide an execution environment in which expressions are evaluated. The majority of the work we’ll do in developing our Angular app is building out the functionality of a scope. Filters In AngularJS, a filter provides a way to format the data we display to the user. Angular gives us several built-in filters as well as an easy way to create our own. We invoke filters in our HTML with the "|" (pipe) character inside the template binding characters {{}}. For instance, let’s say we want to capitalize our string. We can either change all the characters in a string to be capitalized, or we can use a filter. {{ name | uppercase }} We can also use filters from within JavaScript by using the $filter service. For instance, to use the lowercase JavaScript filter: app.controller('DemoController', ['$scope','$filter',function($scope, $filter) { $scope.name =$filter('lowercase')('Ari');
  • 7. }]); currency The currency filter formats a number as currency. In other words, 123 as currency looks like: {{ 123 | currency }}. can use like currency :'$' Currency gives us the option of displaying a currency symbol or identifier. date The date filter allows us to format a date based upon a requested format style. The date formatter provides us several built-in options. If no date format is passed, then it defaults to showing mediumDate (as you can see below). {{ today | date:'medium' }} <!--Aug 09, 2013 12:09:02 PM--> {{ today | date:'short' }} <!--8/9/13 12:09 PM--> {{ today | date:'fullDate' }} <!--Thursday, August 09, 2013--> {{ today | date:'longDate' }} <!--August 09, 2013--> {{ today | date:'mediumDate' }} <!--Aug 09, 2013--> {{ today | date:'shortDate' }} <!--8/9/13--> {{ today | date:'mediumTime' }} <!--12:09:02 PM--> {{ today | date:'shortTime' }} <!--12:09 PM--> Year Formatting Four-digit year: {{ today | date:'yyyy' }} <!--2013--> Two-digit padded year: {{ today | date:'yy' }} <!--13--> One-digit year: {{ today | date:'y' }} <!--2013--> And Many More. The filter filter selects a subset of items from an array of items and returns a new array. This filter is generally used as a way to filter out items for display. For instance, when using client-side searching, we can filter out items from an array immediately. The filter method takes a string, object, or function that it will run to select or reject
  • 8. array elements. If the first parameter passed in is a: Live Demo : http://jsfiddle.net/asP3X/3/ Introduction to Directives : Any attribute that starts with "ng-" is a directive. Use it as "ng-" when usinh in views. ex: • ngRepeat (enter, leave and move animations) use it as ng-repeat • ngInclude (enter and leave animations) use it as ng-include • ngView (enter and leave animations) use it as ng-view • ngIf (enter and leave animations) use it as ng-if • ngSwitch (enter and leave animations) use it as ng-switch • ngClass (addClass and removeClass animations) use it as ng-class • ngShow and ngHide (addClass and removeClass animations for .ng-hide).use it as ng-show, ng-hide. Our First Directive We use directives to extend the html5. <my-directive></my-directive> Directive: angular.module('myApp', []) .directive('myDirective',function() { return{
  • 9. restrict:'E', template:'<a href="http://google.com">Click me to go to Google</a>' } }); So here is the result: And when you see the source :
  • 10. Table 6-2. Directive definition options restrict : Declare how directive can be used in a template as an element, attribute, class, comment, or any combination. priority : Set the order of execution in the template relative to other directives on the element. template : Specify an inline template as a string. Not used if you’re specifying your template as a URL. templateUrl : Specify the template to be loaded by URL. This is not used if you’ve specified an inline template as a string. replace : If true, replace the current element. If false or unspecified, append this directive to the current element. transclude : Lets you move the original children of a directive to a location inside the new template. scope : Create a new scope for this directive rather than inheriting the parent scope.
  • 11. controller : Create a controller which publishes an API for communicating across directives. require : Require that another directive be present for this directive to function correctly. link : Programmatically modify resulting DOM element instances, add event listeners, and set up data binding. compile : Programmatically modify the DOM template for features across copies of a directive, as when used in ng-repeat. Your compile function can also return link functions to modify the resulting element instances. For more on AngularJs, Explore the site http://angularjs.org/. and can find many tutorials and blogs. Have a support in stackoverflow: http://stackoverflow.com/questions/tagged/angularjs