angular js introduction by tania gonzales

44
AngularJS Sessions INTRODUCTION

Upload: thoughtworks

Post on 13-Jan-2015

471 views

Category:

Technology


2 download

DESCRIPTION

AngularJS Introduction Presentation. It covers some basic concepts around AngularJS like controllers, services, etc and some best practices learned along the way. Code is available in github: https://github.com/taniadgv/contactworks

TRANSCRIPT

Page 1: Angular js introduction by Tania Gonzales

A n g u l a r J S S e s s i o n s

INTRODUCTION

Page 2: Angular js introduction by Tania Gonzales

GOALS FOR TODAY

2

What is AngularJS ? Conceptual overview

Why and when should I use it ?

Testing aspects

http://angularjs.org

Page 3: Angular js introduction by Tania Gonzales

CONCEPTUAL OVERVIEW

3

AngularJS is a structural framework for dynamic web applications.

Page 4: Angular js introduction by Tania Gonzales

CONCEPTUAL OVERVIEW

4

Like any abstraction, it comes at a cost of flexibility. Not every app is a good fit for Angular

Page 5: Angular js introduction by Tania Gonzales

CONCEPTUAL OVERVIEW

5

MVC done right

Page 6: Angular js introduction by Tania Gonzales

CONCEPTUAL OVERVIEW

6

A declarative user interface

Page 7: Angular js introduction by Tania Gonzales

CONCEPTUAL OVERVIEW

7

Data models are JavaScript objectsSCOPES

Page 8: Angular js introduction by Tania Gonzales

CONCEPTUAL OVERVIEW

8

Behavior with directives.

DOM manipulation where they belong!

http://www.thoughtworks.com/radar/#/techniques/698

This involves aggressively restricting all DOM access (which usually translates to all jQuery usage) to a thin 'segregation layer'. One pleasant side-effect of this approach is that everything outside of that segregated DOM layer can be tested rapidly in isolation

from the browser using a lean JavaScript engine such as node.js.

Page 9: Angular js introduction by Tania Gonzales

CONCEPTUAL OVERVIEW

9

Flexibility with Filters

Page 10: Angular js introduction by Tania Gonzales

CONCEPTUAL OVERVIEW

10

Context aware communication

Page 11: Angular js introduction by Tania Gonzales

CONCEPTUAL OVERVIEW

11

You will write less code.

Yes you will

Registering callbacks Manipulating HTML DOM programmatically

Marshaling data to and from the UI

Writing tons of initialization code just to get started

Page 12: Angular js introduction by Tania Gonzales

CONCEPTUAL OVERVIEW

12

Designers tend to love it. HTML stays declarative

Page 13: Angular js introduction by Tania Gonzales

CONCEPTUAL OVERVIEW

INVERSION OF CONTROL through

DEPENDENCY INJECTION

PLUS GOOD TESTING/MOCKING TOOLS

TESTABILITY!13

Page 14: Angular js introduction by Tania Gonzales

CONCEPTUAL OVERVIEW

14

MODULEMODULE

CONFIG FILTER DIRECTIVE FACTORY CONTROLLER

ROUTES SERVICE

PROVIDER

VALUE

Page 15: Angular js introduction by Tania Gonzales

CONCEPTUAL OVERVIEW

15

SHOW TIME!

Page 16: Angular js introduction by Tania Gonzales

CONCEPTUAL OVERVIEW

16

DIRECTIVE

DIRECTIVE

"{{ name }}" is a binding expression!

Page 17: Angular js introduction by Tania Gonzales

CONCEPTUAL OVERVIEW

TWO WAY DATA BINDING

TEMPLATE

VIEW

COMPILE

MODEL

LINK

17

Page 18: Angular js introduction by Tania Gonzales

CONCEPTUAL OVERVIEW

18

This example contains bad practices. It was created for educational purposes only!

FILTER

Page 19: Angular js introduction by Tania Gonzales

CONCEPTUAL OVERVIEW

19

MODULEMODULE

CONFIG

FILTER

DIRECTIVE FACTORY

CONTROLLERROUTES

SERVICE

PROVIDERS

Page 20: Angular js introduction by Tania Gonzales

CONCEPTUAL OVERVIEW

20

Page 21: Angular js introduction by Tania Gonzales

CONCEPTUAL OVERVIEW

21

Services Providers

Directives

Filters

Config

Controllers

Factories

Page 22: Angular js introduction by Tania Gonzales

CONTROLLERS

22

Page 23: Angular js introduction by Tania Gonzales

CONCEPTUAL OVERVIEW

23

Services Providers

Directives

Filters

Controllers

Factories Config

Page 24: Angular js introduction by Tania Gonzales

CONCEPTUAL OVERVIEW

24

Services Providers

Directives

Filters

Controllers

Factories Config

Page 25: Angular js introduction by Tania Gonzales

SERVICES/FACTORIES

25

Page 26: Angular js introduction by Tania Gonzales

CONCEPTUAL OVERVIEW

If you want your function to be called like a normal function, use factory. If you want your

function to be instantiated with the new operator, use service.

26

Page 27: Angular js introduction by Tania Gonzales

CONCEPTUAL OVERVIEW

27

Services ProvidersDirectives

Filters

Controllers

Factories Config

Page 28: Angular js introduction by Tania Gonzales

CONCEPTUAL OVERVIEW

28

Features Factory Service Value Constant Provider

Can have dependencies yes yes no no yes

Object available in config phase no no no yes yes

Can create functions / primitives yes no yes yes yes

Page 29: Angular js introduction by Tania Gonzales

CONCEPTUAL OVERVIEW

29

Services Providers

DirectivesFilters

Controllers

Factories Config

Page 30: Angular js introduction by Tania Gonzales

DIRECTIVES

30

Page 31: Angular js introduction by Tania Gonzales

CONCEPTUAL OVERVIEW

31

Services Providers

DirectivesFilters

Controllers

Factories Config

Page 32: Angular js introduction by Tania Gonzales

32

Page 33: Angular js introduction by Tania Gonzales

CONCEPTUAL OVERVIEW

33

Services Providers

Directives

Filters

Controllers

Factories Config

Page 34: Angular js introduction by Tania Gonzales

CONFIG FILE

34

Page 35: Angular js introduction by Tania Gonzales

SOME BEST PRACTICES

GOOD PRACTICES

35

Page 36: Angular js introduction by Tania Gonzales

SOME BEST PRACTICES

Controllers and Services should not reference the DOM

36

Page 37: Angular js introduction by Tania Gonzales

SOME BEST PRACTICES

Controllers should have view behavior

37

Page 38: Angular js introduction by Tania Gonzales

SOME BEST PRACTICES

Services should have reusable logic, independent of the view

38

Page 39: Angular js introduction by Tania Gonzales

SOME BEST PRACTICES

Scope should be read-only in the templates

39

Page 40: Angular js introduction by Tania Gonzales

SOME BEST PRACTICES

Be careful with simple examples.

!

Your architectures should reflect the system, not the frameworks you used in your system

Uncle Bob - Screaming Architecture

40

Page 41: Angular js introduction by Tania Gonzales

41

ECOSYSTEM

NG (core) ngAnimate

ngRoute ngResource

ngCookies

ngTouch

ngSanitize

ngMock

http://ngmodules.org/

Page 42: Angular js introduction by Tania Gonzales

REFERENCES

42

▫︎ http://docs.angularjs.org/guide : Angular official documentation, it used to be very poor with very simples examples but is getting better in content although still using the same basics examples. !

!▫︎https://github.com/angular/angular.js/wiki : Very good “articles" to understand better what angular is doing under the hood, like managing scopes and directives.

!!▫︎ http://www.thinkster.io/pick/GtaQ0oMGIl: "A Better Way to Learn AngularJS”

: Very nice website that puts together a lot of good resources to learn AngularJs from scratch.

!!▫︎http://www.youtube.com/angularjs: AngularJs official youtube channel where

they share and live-stream their presentations. !

Page 43: Angular js introduction by Tania Gonzales

REFERENCES

43

▫︎https://egghead.io/ : Videos with very simple explanation of the angular world such as directives, scope, controllers, very simple to start to understand what angular can do for you but no how it does it.

!!▫︎http://joelhooks.com/ : Blog where you can find some very interesting articles

about AngularJs such as "Modeling Data and State in Your AngularJs Application” !!▫︎AngularJs (O'Reilly, Brad Green & Shyam Seshadri): Nice book to go deeper into the AngularJs concepts and what it has to offer.

!!▫︎Javascript: the good parts (O'Reilly, Douglas Crockford)

Page 44: Angular js introduction by Tania Gonzales

Questions? !

Renan Martins [email protected]

!Tania Gonzales

[email protected]

THANK YOU