Angular JS Training: Shivakanth Cheripelli
Angular JS Training: Shivakanth Cheripelli
Shivakanth Cheripelli
Agenda
1. Introduction to Angular JS
2. Whats new and different about Angular JS
3. Angular JS Framework (Model-View)
4. How you should be thinking about Angular
5. Using Angular with ASP.NET MVC
6. Creating and Angular View inside and MVC View
7. Using Angular inside MVC Layouts
8. Interpolation and Controllers
9. Built in Directives
10. How to think about Directives
11. Breaking down your first Directive
12. Working more on Directives
1.
2.
3.
4.
5.
ngRepeat/Tables,
ngClass, ngTemplate and ngInclude
ngModel, $Scope.$Watch
Disadvantages of Scope watcher
ngcloak
Agenda
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
Getting Started
*** 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 the
page, and styles the content before displaying it to end user. All of this
work happens behind the scenes.
What is SPA?
SPA Lifecycle
What Is AngularJS
1. It is a framework that is primarily used to build single-page web applications
2. Client-side technology, written entirely in JavaScript. It works with the long
established technologies of the web (HTML, CSS, and JavaScript) to make the
development of web apps easier and faster than ever before.
3. AngularJS makes it incredibly easy to build interactive, modern web
applications by increasing the level of abstraction between the developer
and common web app development tasks.
Best Practices
1. Best
1.
2.
3.
4.
Practices
MV* separation
DRY
Dont write hacky solutions
Dont try to re-invent the wheel
Download
AngularJS
Angular Architecture
One of the most confusing adjustments we need to make is learning how to think
about structuring the application
2.
3.
Directory Structure
1.
2.
Modules
1.
Modularize on function
2.
Modularize on functionality
Controllers
1.
4.
Directives
5.
Testing
Directory Structure
Recommended directory structure
*** I recommend, using a tool called Grunt to concatenate project files together in a single file for production
2.
The following methods are valid ways to break up our functionality by modules:
Modularizing on function
.
The most recommended method. Divide the modules by feature. When we break
up our application by feature, we intend to focus on the module function, rather
than the types of functions were including.
*** In our production applications, we use this method of writing modular code and its highly recommend.
Divide the modules by type. We need to inject 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 subdivides the functionality that well need to account for
when writing specs (tests).
*** One issue with this method is that it sometimes leaves us with a bunch of incredibly small modules. This outcome wont hurt
performance, but it can be cumbersome to develop.
http://angular-tips.com/blog/2013/08/watch-how-the-apply-runs-a-digest/
Demo
1. How to setup AngularJs application
2. Interpolation and controllers
3. Built-in Directives
4. ngRepeat
5. ngClass, ngTemplate and ngInclude
6. ngModel
7. $scope.$watch
8. Disadvantages of scope watcher
9. ngCloak
Caching in Angular
2. put()
method allows us to put any javascript object into the cache
Eg: cache.put("hello", "world");
3. get()
method gives us access to the cache value for a key
Eg: cache.get("hello");
4. remove()
removes a key-value pair from the cache
Eg: cache.remove("hello");
5. removeAll()
function resets the cache and removes all cached values
6. destroy()
method removes all references of this cache from the cache registry.
Disk
Eviction algorithm
LRU
Life span
Support for
revalidation
No
Yes
Requires
cooperation of
remote server
No
Yes
Example
Caching Demo
Security in Angular
Security in Angular
Strict Contextual Escaping: the $sce Service
In the controller:
Converting to a
trusted HTML
$sce API
The getTrusted() method takes two arguments:
$sce Parse
Similar to the $parse service, the parse method converts an Angular
expression into a function. If the expression is a literal constant, it calls the
$parse service; otherwise, it calls the $sce.getTrusted() service
The $sce library has a few helper methods for the parse() method
Configuring $sce
Security Demo
ngRepeat Documentation
Factory Demo