introduction to angularjs

20
Introduction to By Ahmed EL-Harouny 21 August 2014

Upload: ahmed-elharouny

Post on 19-Jun-2015

1.488 views

Category:

Software


1 download

DESCRIPTION

Slides of a one hour presentation on: Introduction to AngularJs What is AngularJS? Why? Getting Started AngularJS Building Blocks Controllers Directives Services Scope

TRANSCRIPT

Page 1: Introduction to AngularJs

Introduction to

By Ahmed EL-Harouny21 August 2014

Page 2: Introduction to AngularJs

Page / Copyright ©2014 by Readify Pty Ltd2

Agenda› What is AngularJS?

› Why?

› Getting Started

› AngularJS Building Blocks

› Controllers

› Directives

› Services

› Scope

Page 3: Introduction to AngularJs

Page / Copyright ©2014 by Readify Pty Ltd3

What is AngularJS?• A JavaScript framework for building client side

applications that runs in the browser.• Started by Google but quickly became a popular open

source project.• It aims to simplify development, maintaining and testing

applications.

Page 4: Introduction to AngularJs

Page / Copyright ©2014 by Readify Pty Ltd4

Why?

• Dependency Injection• Data Binding• Routing• Templates• MVC or MVVM• Ajax• Animation• And more!

Page 5: Introduction to AngularJs

/ Copyright ©2014 by Readify Pty Ltd5Page

Getting StartedDemo (link)

Page 6: Introduction to AngularJs

Page / Copyright ©2014 by Readify Pty Ltd6

AngularJS Building Blocks• Modules• Controllers• Directives• Filters• Services• Configs• Routes

Services Recipes Constant

Page 7: Introduction to AngularJs

Page / Copyright ©2014 by Readify Pty Ltd7

Modules- A module is a logical container for the different parts of your app

– controllers, services, filters, directives, etc.- A module is not a namespace.

DependenciesName

Page 8: Introduction to AngularJs

Page / Copyright ©2014 by Readify Pty Ltd8

Modules

Page 9: Introduction to AngularJs

/ Copyright ©2014 by Readify Pty Ltd9Page

ModulesDemo (link)

Page 10: Introduction to AngularJs

Page / Copyright ©2014 by Readify Pty Ltd10

Controllers- A Controller is a JavaScript constructor function that is used to

work with scope (view model).- Controllers are attached to DOM using ng-controller directive.

Name DependenciesConstruction Function

Page 11: Introduction to AngularJs

/ Copyright ©2014 by Readify Pty Ltd11Page

ControllersDemo (link)

Page 12: Introduction to AngularJs

Page / Copyright ©2014 by Readify Pty Ltd12

DirectivesDirectives are markers on a DOM element (such as an attribute, element name, comment or CSS class) that tell AngularJS to attach a specified behavior to that DOM.

Built-In Directives

Page 13: Introduction to AngularJs

Page / Copyright ©2014 by Readify Pty Ltd13

DirectivesCustom Directives

- Custom directive can be used to provide a declarative markup approach and reusability.

- There are many ways to declare a directive in markup using (HTML attributes, elements, comments and CSS classes).

- Prefixing directive names to prevent confusion with other HTML attributes and elements is a must.

Page 14: Introduction to AngularJs

/ Copyright ©2014 by Readify Pty Ltd14Page

DirectivesDemo (link)

Page 15: Introduction to AngularJs

Page / Copyright ©2014 by Readify Pty Ltd15

Services- Services is a way to organize and share code across app.- Services are lazy initialized and singleton.

Built-In Services• $http• $log• $window

Custom Services

Page 16: Introduction to AngularJs

/ Copyright ©2014 by Readify Pty Ltd16Page

ServicesDemo (link)

Page 17: Introduction to AngularJs

Page / Copyright ©2014 by Readify Pty Ltd17

Scope- Scopes are driven by directives.- Any scope belongs exactly to one DOM element.

Page 18: Introduction to AngularJs

Page / Copyright ©2014 by Readify Pty Ltd18

Scope- AngularJS will always create a root scope driven by the ng-app

directive.

ng-app

ng-controller

ng-controller

Page 19: Introduction to AngularJs

/ Copyright ©2014 by Readify Pty Ltd19Page

Tips• Prefix object names.• Install Batarang chrome extension.• Know all ng-* directives.• Read Developer Guide (link).  • Use chrome.

Page 20: Introduction to AngularJs

Thank you