34
BUILDING SINGLE-PAGE WEB APPLICATION WITH ANGULARJS DUY LAM KMS TECHNOLOGY MAR 2014

Building Single-page Web Applications with AngularJS

Embed Size (px)

DESCRIPTION

In recent years, a modern approach for building client-centric applications, Single-Page Web Applications, has become well-known in our developer community. As a result, there are several new frameworks that have made their way to the professional developer’s landscape. AngularJS is a new framework that radically changes the way developers build a web application. It is one of the most ideal alternatives that offers a powerful foundation to build your web application. This slides is dedicated to developers who want to learn the best practices in single-page approaches and how to apply them with AngularJS.

Citation preview

Page 1: Building Single-page Web Applications with AngularJS

BUILDING SINGLE-PAGE WEB APPLICATION WITH ANGULARJS

DUY LAMKMS TECHNOLOGY

MAR 2014

Page 2: Building Single-page Web Applications with AngularJS

AGENDA

Single-page Web App

AngularJS

Takeaway

Page 4: Building Single-page Web Applications with AngularJS

OBJECTIVES

Understand the Single-page approach and its benefits

Understand how well AngularJS supports in building Single-page App

Page 5: Building Single-page Web Applications with AngularJS

AGENDA

Single-page Web App

AngularJS

Takeaway

Page 6: Building Single-page Web Applications with AngularJS

Multi-page web application

SINGLE-PAGE WEB APPLICATION

Single-page web application

Page 8: Building Single-page Web Applications with AngularJS

SPA BENEFITS

Runs faster Gives better UX Is able to operate offline (thanks to HTML5) Uses less network bandwidth

Page 9: Building Single-page Web Applications with AngularJS

SPA DRAWBACKS

Site content becomes SEO-unfriendly Insecure application code Aware navigation browser buttons: Back,

Forward and Reload Run well in browsers compatible with HTML5

History API

Page 10: Building Single-page Web Applications with AngularJS

NOTABLE FRAMEWORKS

http://todomvc.com

ASP.NET Single Page Application

Page 11: Building Single-page Web Applications with AngularJS

AGENDA

Single-page Web App

AngularJS

Takeaway

Page 12: Building Single-page Web Applications with AngularJS

ANGULARJS

Why AngularJSAngularJS conceptsDependency Injection & “recipe” in Injector

serviceDirectives & Filters

Page 13: Building Single-page Web Applications with AngularJS

WHY ANGULARJS

First release v0.9.0 on Oct, 2010 Maintained by Google and community Active development: 03 new releases per

month MIT license (like jQuery) (shameless ad -:) Many killer features

Page 14: Building Single-page Web Applications with AngularJS

DEMO

Page 15: Building Single-page Web Applications with AngularJS

ANGULARJS

Why AngularJSAngularJS conceptsDependency Injection & “recipe” in Injector

serviceDirectives & Filters

Page 16: Building Single-page Web Applications with AngularJS

HELLO WORLD

Page 17: Building Single-page Web Applications with AngularJS

MVC ARCHITECTURE

View(template)

ControllerModel

Two-waybinding

<html></html>

Update

Compile Interact

Routelink link

Page 18: Building Single-page Web Applications with AngularJS

EXPLORE THE CODE

Initialize AngularJS Controllers, Views and Routes Two-way binding in Model and

View Interaction between View and

Controller

Page 19: Building Single-page Web Applications with AngularJS

ANGULARJS

Why AngularJSAngularJS conceptsDependency Injection & “recipe” in Injector

serviceDirectives & Filters

Page 20: Building Single-page Web Applications with AngularJS

USE (INJECT) BUILT-IN SERVICES

Use HTTP and Cookie built-in services

Page 21: Building Single-page Web Applications with AngularJS

DEPENDENCY INJECTION IN NUTSHELL

Dependency is handed to the component

AngularJS Injector service

Page 22: Building Single-page Web Applications with AngularJS

ANGULARJS INJECTOR SERVICE

Injector is responsible for creating two types of objects: User-defined Objects: – We register a “recipe” to instruct Injector in how

to create objects– Recipe types: Value, Factory, Service, Provider

and Constant Specialized Objects: Controllers, Directives,

Filters and Animations

Page 23: Building Single-page Web Applications with AngularJS

INJECT DEPENDENCY IN ANGULARJS

Elements to have dependencies: - Controller, Directive, Filter and Animation- Factory, Service and Provider

Elements can be injected (recipe): Service, Provider, Value, Factory and Constant

Page 24: Building Single-page Web Applications with AngularJS

EXPLORE THE CODE

Register a recipeService vs. Factory

1

2

Page 25: Building Single-page Web Applications with AngularJS

ANGULARJS

Why AngularJSAngularJS conceptsDependency Injection & “recipe” in Injector

serviceDirectives & Filters

Page 26: Building Single-page Web Applications with AngularJS

DIRECTIVES

are markers on a DOM element (an attribute or an element name)

attach behaviors to that DOM element and/or transform the DOM element (and its children)

Page 27: Building Single-page Web Applications with AngularJS

DIRECTIVES

Template

Compiled view

Page 28: Building Single-page Web Applications with AngularJS

FILTERS

“format the value of an expression for display to the user”

Page 29: Building Single-page Web Applications with AngularJS

EXPLORE THE CODE

Implement directives Implement filters

Page 30: Building Single-page Web Applications with AngularJS

AGENDA

Single-page Web App

AngularJS

Takeaway

Page 31: Building Single-page Web Applications with AngularJS

WEB APP DEVELOPMENT

Approaches: Multi-page vs. Single-page Highlight Single-page benefits:

Runs faster Has better UX

Single-page drawbacks: SEO-unfriendly Insecure application code

Page 32: Building Single-page Web Applications with AngularJS

KILLER ANGULARJS FEATURES

MVC architecture Dependency Injection Customized HTML markers (tags and

attributes)

Page 33: Building Single-page Web Applications with AngularJS

REFERENCES

Source code of demo app: https://github.com/kms-technology/angularjs

Demo app url: http://kms-technology.github.io/angularjs/

Page 34: Building Single-page Web Applications with AngularJS

THANK YOU

© 2014 KMS Technology