sas training day 1

69
7/23/2019 SAS Training Day 1 http://slidepdf.com/reader/full/sas-training-day-1 1/69 ShivakanthCheripelli Angular JS Training

Upload: karthik

Post on 19-Feb-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 1/69

Shivakanth Cheripelli

Angular JS Training

Page 2: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 2/69

1.Introduction to Angular JS

2.What’s new and different about Angular JS3.Angular JS Framework (Model-View)4.How you should be thinking about Angular5.Using Angular with ASP.NET MVC6.Creating and Angular View inside and MVC View

7.Using Angular inside MVC Layouts8.Interpolation and Controllers9.Built in Directives10.How to think about Directives11.Breaking down your first Directive

12.Working more on Directives1. ngRepeat/Tables,2. ngClass, ngTemplate and ngInclude3. ngModel, $Scope.$Watch4. Disadvantages of Scope watcher5. ngcloak

Agenda

Page 3: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 3/69

13.Deep linking in an MVC

14.Compile and Link Function15.Directive communication Channels16.Built in Filter and Customer Filters17.Constants and Values18.How to think about Services19.Factories20.Services21.Providers22.Decoraters23.Dependency Injection

Agenda

Page 4: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 4/69

Getting Started…

Page 5: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 5/69

What is a Browser & how web pages get to thebrowser?

*** The browser gets the HTML text of the page, parses it into a structure

that is internally meaningful to the browser, lays out the content of thepage, and styles the content before displaying it to end user. All of thiswork happens behind the scenes.

Page 6: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 6/69

What is SPA?

Page 7: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 7/69

SPA Lifecycle

Page 8: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 8/69

Page 9: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 9/69

Page 10: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 10/69

Page 11: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 11/69

. !t is a framework that is primarily used to build single"page web applications

#. $lient"side technology, written entirely in %a&a'cript. !t works with the longestablished technologies of the web (HTML, $'', and %a&a'cript) to make thede&elopment of web apps easier and faster than e&er before.

. Angular%' makes it incredibly easy to build interacti&e, modern webapplications by increasing the le&el of abstraction between the de&eloperand common web app de&elopment tasks.

What Is AngularS

Page 12: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 12/69

. +est ractices. M-* separation#. /0

. on1t write hacky solutions23. on1t try to re"in&ent the wheel2

#. on1t write bad code. erformance#. /eusability. '4uare peg, round hole

. Test. 5rite the best tests6#. oesn1t7 ha&e to be T

3. +roaden your understanding. Learning cur&e should be steep6#. ractice being curious

. /efactor6

8. /ead the source code6. $onsumable#. 9rror messages are bad6. issect the source

Best Practices

Page 13: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 13/69

!ownloadAngularS

Page 14: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 14/69

Page 15: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 15/69

Angular Architecture

:ne of the most confusing ad;ustments we need to make is learning how to think

about structuring the application

Structuring your Angular application

.

irectory 'tructure. How to structure your de&elopment application

#. How to structure your test directory

#. Modules

. Modulari<e on function

#. Modulari<e on functionality

. $ontrollers

. 'haring data between controllers

3. irecti&es

8.  Testing

Page 16: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 16/69

!irectory Structure"eco##ended directory structure

*** ! recommend, using a tool called =runt to concatenate pro;ect >les together in a single >le for production

"eco##ended test directorystructure

Page 17: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 17/69

$odulari%ing your angular application

*** !n our production applications, we use this method of writing modular code and it1s highly recommend.

. A module is the kernel of functionality for Angular apps

#. Modules are a great way to reduce global scope noise

The following methods are valid ways to break up our functionality by modules:

$odulari%ing on function

.  The most recommended method. i&ide the modules by feature. 5hen we break

up our application by feature, we intend to focus on the module function, ratherthan the types of functions we1re including.

Page 18: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 18/69

$odulari%ing your angular application

*** :ne issue with this method is that it sometimes lea&es us with a bunch of incredibly small modules. This outcome won1t hurtperformance, but it can be cumbersome to de&elop.

$odulari%ing on functionality

i&ide the modules by type. 5e need to in;ect these modules as dependencies for

our main app, which makes it incredibly easy to set up tests for each module type

and also isolates and subdi&ides the functionality that we1ll need to account forwhen writing specs (tests).

Page 19: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 19/69

he 'digest Loop and !irty chec(ingHow do we get the magical data binding to work in only a few lines of code?

Disclaimer: !t1s &ery important that we understand how the @digest loop works and what is dirty checking

httpBBangular"tips.comBblogB#CBCDBwatch"how"the"apply"runs"a"digestB

Page 20: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 20/69

. How to setup Angular%s application

#. !nterpolation and controllers

. +uilt"in irecti&es

3. ng/epeat

8. ng$lass, ngTemplate and ng!nclude

E. ngModel

F. @scope.@watch

D. isad&antages of scope watcher

G. ng$loak

!e#o

Page 21: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 21/69

)aching in Angular

Page 22: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 22/69

Why should we cache* anyway?

.  To reduce A! calls,

#.  To create scalable apps,

.  To impro&e performance etc2

Introducing the 'cache+actory

!t1s a feature out of the box pro&ided by Angular%'.

)aching 'http re,uests in Angular

 0ah6 ! cached the data

/etrie&e data fromcache

Page 23: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 23/69

What )ache pro-ides for us* out of the bo.?

. info()

returns the !, si<e, and options of the cache ob;ect

#. put()

method allows us to put any ;a&ascript ob;ect into the cache

9g cache.put(hello, world)I

. get()

method gi&es us access to the cache &alue for a key 

9g: cache.get(hello)I

3. remo&e()

remo&es a key"&alue pair from the cache

9g cache.remo&e(hello)I

8. remo&eAll()

function resets the cache and remo&es all cached &alues

E. destroy()

method remo&es all references of this cache from the cache registry.

/ow to #anage cache?

Page 24: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 24/69

AngularS cache -s browser /P cache

Angular 'cache+actory Browser /P cache0)hro#e1

 %a&ascript heap memory isk

2-iction algorith# Least recently used (L/J) L/J

Life span until page refresh etermined by HTT headers

Support forre-alidation

Ko 0es

"e,uirescooperation ofre#ote ser-er

Ko 0es

2.a#ple

Page 25: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 25/69

)aching !e#o

Page 26: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 26/69

Security in Angular

Page 27: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 27/69

Strict )onte.tual 2scaping3 the 'sce Ser-ice

A&ailable by default in Angular &ersion .# and higher

$sce is a fantastic service that allows us to write whitelisted, secure codeby default and goes a long way toward helping us prevent XSS and other

vulnerabilities. iven this power, it!s important to understand what it isthat we!re doing so we can use it wisely 

Security in Angular

-ery dangerous code and highly &ulnerable for threats

Page 28: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 28/69

)on-erting user input

!n the controller

$on&erting to atrusted HTML

Page 29: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 29/69

The getTrusted() method takes two arguments:

'sce API

Page 30: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 30/69

'imilar to the @parse ser&ice, the parse method con&erts an Angular

expression into a function. !f the expression is a literal constant, it calls the@parse ser&iceI otherwise, it calls the @sce.getTrusted() ser&ice

'sce Parse

•  The @sce library has a few helper methods for the parse() method

Page 31: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 31/69

)on4guring 'sce

Page 32: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 32/69

Security !e#o

Page 33: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 33/69

5pti#i%ing Angular Apps

Page 34: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 34/69

5hy to optimi<e?

5pti#i%ing Angular Apps

Page 35: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 35/69

What to 5pti#i%e?

. :ptimi<e the @digest Loop

#. :ptimi<e ng"repeat

. :ptimi<e @watch unctions

3. Jse +indonce the watcher is remo&ed once the expression stabili<es inthe J!.

8. :ptimi<e iltersE. igure out Jnchanging ata and cache it.

F. :ptimi<e your age Load

. Mini>cation

#. Jtili<e the @template$ache

5pti#i%ing Angular Apps

Page 36: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 36/69

5pti#i%ing the 'digest Loop

Page 37: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 37/69

Page 38: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 38/69

Page 39: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 39/69

Page 40: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 40/69

Page 41: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 41/69

Page 42: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 42/69

Page 43: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 43/69

 AngularS API "eference for !irecti-es

Page 44: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 44/69

Page 45: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 45/69

ng"epeat !ocu#entation

Page 46: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 46/69

Page 47: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 47/69

6sing +ilters !e#o

Page 48: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 48/69

Page 49: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 49/69

Page 50: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 50/69

Page 51: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 51/69

Page 52: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 52/69

Page 53: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 53/69

Page 54: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 54/69

Page 55: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 55/69

Page 56: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 56/69

 AngularJS extends HTML with new attributes. AngularJS is perfect for Single Page Applications (SPAs). AngularJS is easy to learn.

What You Should Already KnowBefore you study AngularJS, youshould have a basic understanding of:HTMLCSSJavaScript

MVC Training Deloitte

Page 57: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 57/69

Page 58: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 58/69

Page 59: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 59/69

Page 60: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 60/69

Page 61: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 61/69

!e4ning "outes !e#o

Page 62: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 62/69

Page 63: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 63/69

Page 64: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 64/69

actually tweaked the route ;ust a little bit

Page 65: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 65/69

Page 66: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 66/69

Page 67: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 67/69

+actory !e#o

Page 68: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 68/69

Page 69: SAS Training Day 1

7/23/2019 SAS Training Day 1

http://slidepdf.com/reader/full/sas-training-day-1 69/69