8. 8SinglePageApplications
Webapplicationscomposedof a singlepage
Views(HTML Fragments)aredynamicallyloaded into the page
Betteruserexperience(no reloads!)
Calls to the serveraredone asynchronouslybehind the scenes
Requireartificialhandling of browserhistory, navigation and
bookmarks
WHATISANGULARJS? /56
9. 9Model-View-Whatever
Somecallit MVC, othersMVVM...
In the end, the namedoes not
matter. It handles separationof
concernsefectivelyseparating
presentationlogicfrombusiness
logicand presentationstate.
Whatevermeans “whatever
worksfor you”.
WHATISANGULARJS? /56
Read More: https://plus.google.com/+AngularJS/posts/aZNVhj355G2
Model View
Whatever
22. 22Databinding
Automatic synchronizationof data betweenthe Modeland the View.
MAINCONCEPTS /56
Read More: https://docs.angularjs.org/guide/databinding
View
Template Model
One-time
merge
One-WayDataBinding
View
Template
Model
Continuous updates
Model is Single-Source-of-Truth
Compile
Changes to Model
updates View
Changes to View
updates Model
Two-WayDataBinding
24. 24Scope
Objectthat refersto the applicationModel
Valuesstored in variablesin the Scopebelong to the Model
The glue betweenthe Controllerand the View
Scopesarehierarchicaland followthe
DOM structureof the application
EveryAngular applicationhas a root
scope($rootScope)mapped to the
elementlinked to ngApp directive
MAINCONCEPTS /56
Read More: https://docs.angularjs.org/guide/scope
25. 25Controllers
JavaScriptconstructorfunctions used to augmentthe Scope
Newchild scopeis createdand
injectedas a constructor
parameter($scope)
MAINCONCEPTS /56
Read More: https://docs.angularjs.org/guide/controller
31. 31Filters
A filterformatsthevalueof anexpressionfor display to the user
Can be used in view templates,controllers,servicesand directives
You can createyour ownfilters (in a module)
Built-in filters:
MAINCONCEPTS /56
Read More: https://docs.angularjs.org/guide/filter
Currency
Date
Filter
Json
LimitTo
Lowercase
Number
OrderBy
Uppercase
34. 34Creatingfilters
angular.module('MyFilterModule', []).
filter('myfilter', function() {
return function(input) {
...
return output;
};
});
MAINCONCEPTS/FILTERS /56
Read More: https://docs.angularjs.org/guide/filter
User the filter provider to
create a new filter in the
module
Name the filter
Return the filter function. The first
argument is the input value.
Additional arguments can be used.
36. 36Services
Reusablebusiness logiccomponentes,independentof views,wired
togetherusing dependencyinjection(DI).
Singletonsgeneratedby a servicefactory.
Angular only instantiatesa serviceif thereis a dependencyfor it.
Built-in servicesstart with $.
Examples:$log, $http, $filter,$exceptionHandler
MAINCONCEPTS /56
Read More: https://docs.angularjs.org/guide/services
37. 37Usingaservice
var countryApp = angular.module('countryApp', []);
countryApp.controller('CountryCtrl', ['$scope', '$http', function (scope, http) {
http.get(‘countries.json').success(function(data) {
scope.countries = data;
});
}]);
MAINCONCEPTS/SERVICES /56
Inject $http service using DI
Receive service object
as a parameter
Call method on service
Read More: https://docs.angularjs.org/guide/services
38. 38Creatingaservice
var myModule = angular.module('myModule', []);
myModule.factory('serviceId', function() {
var shinyNewServiceInstance;
//factory function body that constructs shinyNewServiceInstance
return shinyNewServiceInstance;
});
MAINCONCEPTS/SERVICES /56
Return a service instance
Register a new factory function for the service
Read More: https://docs.angularjs.org/guide/services
41. 41Multipleviews
Most applicationsarecomposedof morethan one view
In Single PageApplicationsall viewsare renderedin the same page
(LayoutTemplate)which containsall the commonpage elements
Eachview(PartialTemplate)is placedin its own file and dynamically
loadedinto the LayoutTemplate page
MAINCONCEPTS /56
52. 52Wrappingup
AngularJS is a modular JavaScriptSPA framework
Has a lot of great featuresbut a steeplearningcurve
Greatfor CRUD applicationsbut not suitable for everytype of
application
Worksvery wellwith some JavaScriptlibraries(such as jQuery)but
not so wellwith others
Increasesdeveloperproductivity in small/medium applicationsbut
can be quite heavyfor complexapplications
/56