craftcamp for students - introduction to angularjs

32
Introduction to AngularJS

Upload: craftworkz

Post on 15-Aug-2015

84 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: CraftCamp for Students - Introduction to AngularJS

Introduction to AngularJS

Page 2: CraftCamp for Students - Introduction to AngularJS

Gunther Laurijssens Consultant @laurigun

Page 3: CraftCamp for Students - Introduction to AngularJS

Agenda

● What is AngularJS? ● Why use AngularJS?

● Concepts + demos

●  Tips

Page 4: CraftCamp for Students - Introduction to AngularJS

What is angular?

●  AngularJS IS NOT - a Library - a replacement for HTML, CSS or JS

●  AngularJS IS

- a clientside JavaScript MVC Framework - Extention to HTML with new attributes, custom tags, ..

Page 5: CraftCamp for Students - Introduction to AngularJS
Page 6: CraftCamp for Students - Introduction to AngularJS

Why use angular? ●  Re-usable components ●  Modularity

●  Dependency Injection

●  Two-way Databinding

●  Testing

Page 7: CraftCamp for Students - Introduction to AngularJS

Concepts

●  Expressions

●  Filters

●  Directives

●  Models

●  Modules

●  Controllers

●  2-Way Databinding

●  Services

Page 8: CraftCamp for Students - Introduction to AngularJS

Getting started

1. Include Angular

2. Bootstrap Angular

Page 9: CraftCamp for Students - Introduction to AngularJS

Directives •  Extend HTML to define custom tags, attributes

and classes

•  ng-prefix •  Normalization

ngModel

Recommended HTML5

compliant

Page 10: CraftCamp for Students - Introduction to AngularJS

Directives •  As an attribute (A)

•  As a class (C)

•  As an element (E)

•  As a comment (M)

Page 11: CraftCamp for Students - Introduction to AngularJS

Scopes

•  Exactly ONE root Scope via ng-app

•  Child scopes (controllers, directives)

•  Scope inheritance à Mimic DOM structure

•  Determine access to models

Page 12: CraftCamp for Students - Introduction to AngularJS

Models •  Encapsulate application data

•  Variable on Scope

•  ngModel directive

Page 13: CraftCamp for Students - Introduction to AngularJS

Expressions •  JavaScript-like code snippets that are

usually placed in bindings - {{ expression }}

•  Valid expressions - {{ 1 + 1 }} - {{ a + b }} - {{ name }}

Page 14: CraftCamp for Students - Introduction to AngularJS

Filters ●  Formatting values

●  Separated by | (pipe)

●  {{ expression | filter }}

●  Built-in filters: uppercase, lowercase, limitTo, …

Page 15: CraftCamp for Students - Introduction to AngularJS

Templates

HTML + Directives + Filters

View

Compile

Page 16: CraftCamp for Students - Introduction to AngularJS

Modules ●  AngularJS has nothing like a main method

●  Container for custom components

●  Allows us to build re-usable components - Controllers - Services - Filters - Directives

Page 17: CraftCamp for Students - Introduction to AngularJS

Controllers

•  Set up the inital state of $scope object

•  Add behavior to the $scope object

•  Inheritance

Page 18: CraftCamp for Students - Introduction to AngularJS

Controllers

•  Creates a new child scope

•  Scope of view injected in Controllers constructor function

Page 19: CraftCamp for Students - Introduction to AngularJS

$Scope

View Controller

ViewModel

Model

Page 20: CraftCamp for Students - Introduction to AngularJS

2-way databinding

Page 21: CraftCamp for Students - Introduction to AngularJS

Services

●  Extract re-usable code

●  Communicate between controllers

●  Lazily instantiated (Dependency Injection)

●  Singletons

Page 22: CraftCamp for Students - Introduction to AngularJS

Services ●  $rootScope

●  $scope

●  $http ●  $q

●  $log

•  $interval

•  $resource

•  $timeout

•  $window

•  $document

Page 23: CraftCamp for Students - Introduction to AngularJS

Services - Factory

Page 24: CraftCamp for Students - Introduction to AngularJS

Services - Service

Page 25: CraftCamp for Students - Introduction to AngularJS

Tips

Page 26: CraftCamp for Students - Introduction to AngularJS

Modules •  An application level module

•  A module for each Feature

•  A module for each reusable component - Controllers - Services - Filters - Directives

Page 27: CraftCamp for Students - Introduction to AngularJS

Controllers •  Do not use controllers to:

- Manipulate DOM ( à use directives)

- Format input (à use forms)

- Share code or state across Controllers (à use services)

Page 28: CraftCamp for Students - Introduction to AngularJS

Dependencies

•  What happens with Minification?

- Renames function parameters

- How do does compiler know which is which?

Page 29: CraftCamp for Students - Introduction to AngularJS

ngSrc

•  The easy way

•  How it should be written

Page 30: CraftCamp for Students - Introduction to AngularJS

Not covered •  Promises

•  Localization

•  Form Validation

•  Views & Routes

•  Server communication

•  Testing

•  …

Page 31: CraftCamp for Students - Introduction to AngularJS

Resources

•  https://docs.angularjs.org/

•  https://egghead.io/

•  https://thinkster.io/

•  http://www.slideshare.net/craftworkz/

•  https://github.com/craftworkz/ucll-workshop-angularjs

Page 32: CraftCamp for Students - Introduction to AngularJS

Thanks for listening!

Questions?