a gently introduction to angularjs

33

Upload: gregor-woiwode

Post on 12-Jul-2015

635 views

Category:

Software


5 download

TRANSCRIPT

Page 1: A gently introduction to AngularJS
Page 2: A gently introduction to AngularJS

Gregor Woiwode@GregOnNet

Software must fit user needs, not vice versa! #empathic-business

FAVORITE

1

Page 3: A gently introduction to AngularJS

Web Apps?!I can’t!

Of course,I can!

discoversstunned

Page 4: A gently introduction to AngularJS

Downloads

https://github.com/GregOnNet/angular-starter-demos

https://github.com/GregOnNet/angular-cups

Source Code

Page 5: A gently introduction to AngularJS

Search...

+

https://single-page.app/#/list What do we expect from a single-page app?

Reacting fast to user input

Providing comprehensive interactions

Using only one page?

Page 6: A gently introduction to AngularJS

Card - One...

https://single-page.app/#/card/one Mission accomplished - NOT!

Routing between views

Interacting with server side APIs

Binding & Presenting dataSave

Who cares about...

Caching data

Organizing app architecture that scales

Templating multiple views

Page 7: A gently introduction to AngularJS

My personal pains

A B

DC

Framework confetti

Page 8: A gently introduction to AngularJS

My personal pains

Abetter

D

A

Dependencies & Versioning

Page 9: A gently introduction to AngularJS

A

B DC

Choosing one pluggable ecosystem

My personal salvation

Page 10: A gently introduction to AngularJS

What is in the box?

{{ }}

Data Binding

two way

one way

change tracking

Page 11: A gently introduction to AngularJS

Modules

What is in the box?

controllers

factories, services, providers

directives, filter

Page 12: A gently introduction to AngularJS

Dependency Injection

What is in the box?

Page 13: A gently introduction to AngularJS

Routing

What is in the box?

Page 14: A gently introduction to AngularJS

Testing

What is in the box?

Page 15: A gently introduction to AngularJS

What is in the box?

Community

31.3k Stars

~ 96k Videos

~ 63k Questions

11th of November 2014

angularjs.org

Documentation and Tutorials

Page 16: A gently introduction to AngularJS

<html ng-app="demo">

// our awesome app

</html>

Let’s get into code

Page 17: A gently introduction to AngularJS

Intermediate Function Expression - iife

(function() { 'use strict';

// Isolation

})();

Page 18: A gently introduction to AngularJS

Why iife?

var greet = 'Hi!';

script.js

var greet = 'Bye!';

conflict.js

Last man standing

Page 19: A gently introduction to AngularJS

Why iife?

var greet = 'Hi!';

script.js

(function () { 'use strict';

})();

var greet = 'Bye!';

conflict.js

(function () { 'use strict';

})();SAVE

Page 20: A gently introduction to AngularJS

angular .module('app', [

'module', 'feature']);

Defining a module

// … Extend it with // other modules

// Name your module...

Page 21: A gently introduction to AngularJS

angular .module('app') .controller('Persons', Persons);

function Persons() { }

Defining a controller

Page 22: A gently introduction to AngularJS

angular .module('app') .directive('semanticHtml', semanticHtml);

function semanticHtml () { return { restrict : 'E | A | C', template : '<html-template>' };}

Our first directive

// Nearly the same like our // controller, right?

// Watch out!// Directives return a new // object literal

Page 23: A gently introduction to AngularJS

Even more about directives

function semanticHtml () { return { restrict : 'E | A | C', template : '<html-template>' templateUrl: scope: controller: link: };}

Page 24: A gently introduction to AngularJS

angular .module('app') .filter('manipulate', manipulate);

function manipulate() {

return function(input, /* parameters */ ) {

}}

Starting with filters

// Watch out!// Filters return a function.

Page 25: A gently introduction to AngularJS

There are many filters already implemented

https://github.com/a8m/angular-filter

Page 26: A gently introduction to AngularJS

angular .module('app') .factory('dataAccess', dataAccess);

function dataAccess() {

return {

};}

Defining a factory, service, whatever...

// LEGO bricks the angular// way

// Declaring the api of our// service

Page 27: A gently introduction to AngularJS

$injecting a service into a controller

// angular magic

angular .module('app') .controller('Persons', Persons);

Persons.$inject = ['dataAccess'];

function Persons(dataAccess) { }

Page 28: A gently introduction to AngularJS

angular .module('app') .controller('Persons', Persons);

function Persons(dataAccess) { }

$injecting a service into a controller

// still works without $inject

Page 29: A gently introduction to AngularJS

angular .module('app') .controller('Persons', p);

function p(a) { }

$injecting a service into a controller

// But a minifier will break// your app

a cannot be resolved as dataAccess

Page 30: A gently introduction to AngularJS

events

childcontroller

parent controller

$broadcast

$emit

$scope ('eventName');.$emit.$broadcast

Page 31: A gently introduction to AngularJS

events using $rootScope

controller subscriber

controller publisher

$rootScope .$emit('eventName');

$rootScope .$on('eventName' , callback);

Page 33: A gently introduction to AngularJS

Questions?