22
SPA using AngularJS Common Features and Issues

Single Page Applications using AngularJS

Embed Size (px)

Citation preview

Page 1: Single Page Applications using AngularJS

SPA using AngularJSCommon Features and Issues

Page 2: Single Page Applications using AngularJS

Hello world!I am San-tho-sh Kumar Srinivasan

8 Years of Software development experience as full stack developer

3 years developing SPAs using AngularJS

You can find me at:@santhotech inGithub and twitter

Page 3: Single Page Applications using AngularJS

A single-page application (SPA) is a web application or web site that fits on a single web page

with the goal of providing a more fluid user experience similar to

a desktop application -Wikipedia

Page 4: Single Page Applications using AngularJS

Advantages of SPA

▪Easy Separation of Concerns▪Easy Code Maintenance▪Easy to test independently▪Easy to switch server side any time

Specifically with Angular JS

▪ Easy URL routing with HTML5 mode support

▪ Perfect for Prototyping an Idea

Page 5: Single Page Applications using AngularJS

Comparison between SPA and Conventional MVC

Conventional MVC Single Page Applications

URL routing is handled in the Server side

URL routing is handled in the client side

Views are managed and handled by the server

Server responds with all the views in the first request and all view handling is done in cilent

Most of the business logic is done on the server

Most of the business logic is kept on the client side

Server side code is injected in the views in some form

No server side code loads in the client views.

Page 6: Single Page Applications using AngularJS

1Project Structure

How do you get started with a SPA?

Page 7: Single Page Applications using AngularJS

Load it as part of your server side framework

You can handle the call to your ‘root’ URL and load the spa’s index page and let it take care of further requests

Two Common Methods

Go stand alone and load it a independent HTML/JS application

Just create a stand alone angular application and make it respond to root requests. Your angular app makes further requests to data from an API backend.

Page 8: Single Page Applications using AngularJS

Impacts of choosing one or the other method

AuthenticationYou cannot use your server side’s authentication method if you create an independent application.

Request HandlingIf you load your angular app as part of your server side app, you have to be careful on how you separate your rest URLs and your view URLs

File UploadsCross domain file uploads have restrictions and you need to make sure that your server is configured to allow that.

Page 9: Single Page Applications using AngularJS

2CRUD Operations

CRUD operations are a breeze with Angular

Page 10: Single Page Applications using AngularJS

Make use of ngResource module or the RestAngular module

AngularJS comes with several modules and plugins that makes your life easier when working with REST APIs.

Just Rest

Work with Model Objects as you would in the server side

These plugins gives you the ability to work with JS objects as you would on any server side frameworks by adding convenience methods

.create

.update

.delete

.list

.get…

Page 11: Single Page Applications using AngularJS

3Authentication and Authorization

AngularJS makes it easy to handle security

Page 12: Single Page Applications using AngularJS

Choose a Scheme that fits you

Server Side AuthIf your angular app is loaded as part of your server side, you can make use of the same auth scheme

JSON Web TokensIf your app is an independent app, then this is one of the best methods. Most server side frameworks supports this.

OAuth or your OwnYou can also try to roll out your own auth schemes and use it with angular or use one of the available Oauth schemes.

• Microsoft ADALIf you need to use azure active directory ADAL looks promising

Page 13: Single Page Applications using AngularJS

4Make use of Directives

Custom directives enhances angular

applications

Page 14: Single Page Applications using AngularJS

Some common uses of Directives

UI Manipulation

Anything that changes the color, dimensions, or any other physical property of the components

Recurring Components

If there is a component that needs to be used in multiple views, directives can be u

Plugin Wrappers

Jquery plugins that you *have to* use, then you can create a directive to wrap the plugin feature

Page 15: Single Page Applications using AngularJS

5File Uploads

Custom directives enhances angular

applications

Page 16: Single Page Applications using AngularJS

Some things to watch out

Make sure CORS is enabled

Your CORS filter on the server should be enabled on the application/server level or both

CSRF Tokens

Some frameworks have CSRF token verification causing uploads to fail

Ng-file-upload Angular-file-

upload

Common Plugins

Page 17: Single Page Applications using AngularJS

6Lazy Loading Components

Improves load time

Page 18: Single Page Applications using AngularJS

7Watch out for Nested Scopes

Makes it hard to debug

Page 19: Single Page Applications using AngularJS

8Make use of $broadcast and $emit

But don’t over use it

Page 20: Single Page Applications using AngularJS

Other Useful Links

▪ Angular Style guidehttps://github.com/johnpapa/angular-styleguide/

blob/master/a1/README.md▪ Angular Tips and Hints

http://www.bennadel.com/blog/2439-my-experience-with-angularjs---the-super-heroic-javascript-mvw-framework.htm

Page 21: Single Page Applications using AngularJS

Thanks!ANY QUESTIONS?

Page 22: Single Page Applications using AngularJS

CREDITS

Special thanks to all the people who made and released these awesome resources for free:▪ Presentation template by SlidesCarnival▪ Photographs by Unsplash