Www.luxoft.com Angular JS Angular services. www.luxoft.com Dependency injection AngularJS comes with a built-in dependency injection mechanism. You can.

Slides:



Advertisements
Similar presentations
JavaScript & jQuery JavaScript and jQuery introduction.
Advertisements

Dhananjay Microsoft MVP
Struts Basics SSE USTC Qing Ding. Agenda What is and Why Struts? Struts architecture – Controller: Focus of this presentation – Model – View Struts tag.
IIS 7: The Next Generation Web Application Server Platform Michael Volodarsky Program Manager Web Platform and Tools Team Microsoft Corporation.
WSS 3.0 Architecture and Enhancements Ashvini Shahane Member – Synergetics Research Lab.
242/102/49 0/51/59 181/172/166 Primary colors 248/152/29 PMS 172 PMS 137 PMS 546 PMS /206/ /227/ /129/123 Secondary colors 114/181/204.
Using Data Active Server Pages Objectives In this chapter, you will: Learn about variables and constants Explore application and session variables Learn.
Single Page Applications with AngluarJS Bill Wolff Rob Keiser
SUNY Polytechnic Institute CS 490 – Web Design, AJAX, jQueryAngularJS AngularJS is a client-side JavaScript Framework for adding interactivity to HTML.
Introduction Marko Marić, Danulabs
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Eric Vogel Software Developer A.J. Boggs & Company.
AngularJS Routing Routes, Route Parameters, Templates, Location, Navigation SoftUni Team Technical Trainers Software University
Parsley Introduction Kui Huang Oct. 13, Topics Background Dependency Injection Object Lifecycle Message Bus Sample FW Extensions.
The Web Wizard’s Guide To JavaScript Chapter 6 Working with Dates and Times.
Krishna Mohan Koyya Glarimy Technology Services
AngularJS Directives Defining Custom Directives SoftUni Team Technical Trainers Software University
@ScotHillier Web Parts Workflows Pages Libraries App Parts SharePoint-Hosted Apps Provider-Hosted Apps.
Procedures and Functions Computing Module 1. What is modular programming? Most programs written for companies will have thousands of lines of code. Most.
Chapter 6 Object-Oriented Java Script JavaScript, Third Edition.
Flexible hierarchy design proposal. Flexible hierarchy design  Goals  Allow debug plugins to define their own debug element hierarchy and behaviour.
Building Rich Apps with AngularJS on ASP.NET.
Microsoft Virtual Academy Stacey Mulcahy | Technical Evangelist Christopher Harrison | Content Developer.
Functions and Closures. JavaScript Closures Are Everywhere In JS we often want to say “when this thing happens, do something” event driven programming.
2/26/021 Pegasus Security Architecture Author: Nag Boranna Hewlett-Packard Company.
Cairngorm Microarchitecture. Pronunciation Cairngorm (kârn gôrm) n. yellowish-brown variety of quartz, especially found in Scottish Cairngorm mountain.
REVOLUTION TO NEXT GENERATION Struts2.0 20/02/ Avishek Arang ::
Controllers and Markup Controllers, $scope, Markup, Directives, Expressions, Binding, Filters, Validation SoftUni Team Technical Trainers Software University.
Developing Great Dashlets Will Abson About Me Project Lead, Share Extras Alfresco Developer and previously Solutions Engineer DevCon 2011 –
Page 1 Controller Action2.java Struts- config. xml Mappings Business Logic Layer Data Layer View Layer Business Bean 1 Jsp Engine Jsp 1 Action3.java Action4.java.
WikiPlus Configurations Configure WikiPlus elements to your needs.
AngularJS AJAX.
AngularJS Forms & validation. AngularJS form example First.
Krishna Mohan Koyya Glarimy Technology Services
Understand haxejs-angular app How to write app in OOP(Haxe) and Dependency Injection Way(Angular)?
Implementation Struts Framework for well-architectured web applications Model-View-Controller design pattern.
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
Presentation Title Subtitle DSpace UI Prototype 7 Spring, Angular.js, and the DSpace REST API.
AngularJS $resource service. Add angular-resouce: Add the dependency: angular.module('myApp', ['ngResource']); Configure.
SHAREPOINT SATURDAY PRESENTATION by Keith Rimington REAL EXPERIENCES WITH ANGULARJS AND SHAREPOINT.
Getting Started with Angular 2 and TypeScript Nebraska.Code() 2016 Spencer Schneidenbach Ryvit.
Modern Development Technologies in SharePoint SHAREPOINT SATURDAY OMAHA APRIL, 2016.
Developing Great Dashlets Will Abson About Me Project Lead, Share Extras Alfresco Developer and previously Solutions Engineer DevCon 2011 –
Developing Great Dashlets Will Abson About Me Project Lead, Share Extras Alfresco Developer and previously Solutions Engineer DevCon 2011 –
AngularJS. What is AngularJS  Javascript Framework  MVC  for Rich Web Application Development  by Google.
AngularJS and SharePoint
AngularJS Best Practices High Quality SPA Applications SoftUni Team Technical Trainers Software University
ANGULAR 2. JavaScript is a high-level, dynamic, untyped, and interpreted programming language. JavaScript was originally developed in May 1995 by Brendan.
© Luxoft Training. All rights reserved AngularJS Introduction.
REF : Mitch Denny + James Speirs Introduction WHAT IS ANGULARJS.
AngularJS By Alireza Mirian At HasinTech.. Why Angular at first place The reason something like Angular emerges: The path Web Standards have went through.
Chapter 5 Angularjs. Content Overview How to program with Angularjs Directives Expressions Controllers Filters HTML DOM Forms and Includes Ajax Scopes.
Angular JS and SharePoint
Actions and Behaviours
Operating System Structures
Built-in and Custom Services
Extra Course
Jessica Betts, Sophia Pandey, & Ryan Amundson
Angularjs Interview Questions and Answers By Hope Tutors.
Step by Step - AngularJS
Angular (JS): A Framework for Dynamic Web Pages
Introduction to AngularJS
Object-Oriented Programming in PHP
CS5220 Advanced Topics in Web Programming Angular – TypeScript
AngularJS Michael Kang August 20th 2015.
CS5220 Advanced Topics in Web Programming Angular – Services
Web API with Angular 2 Front End
Angular 2 Michael C. Kang.
Chengyu Sun California State University, Los Angeles
02 | Angular Controllers Stacey Mulcahy | Technical Evangelist
Presentation transcript:

Angular JS Angular services

Dependency injection AngularJS comes with a built-in dependency injection mechanism. You can divide your application into multiple different types of components which AngularJS can inject into each other. Modularizing your application makes it easier to reuse, configure and test the components in your application. AngularJS contains the following core types of objects and components: Value Factory Service Provider Constant

Angular layered application architecture

Value var myModule = angular.module("myModule", []); myModule.value("numberValue", 999); myModule.controller("MyController", function($scope, numberValue) { console.log(numberValue); }); A value is a simple object which can be passed to the controllers or services.

Factory Factory is a function that creates values. var myModule = angular.module("myModule", []); myModule.factory("myFactory", function() { return "a value"; }); myModule.controller("MyController", function($scope, myFactory) { console.log(myFactory); });

Service A service in AngularJS is a singleton JavaScript object which contains a set of functions. function MyService() { this.value = 5; this.doIt = function() { console.log("done “+this.value); } var myModule = angular.module("myModule", []); myModule.service("myService", MyService); myModule.controller("MyController", function($scope, myService) { myService.doIt(); // will print “done 5" }); AngularJS do it internally: var theService = new MyService();

Service vs. Factory

Injecting Values Into a Service myModule.value("myValue", "12345"); function MyService(myValue) { this.doIt = function() { console.log("done: " + myValue); } myModule.service("myService", MyService); Notice how the parameter to the MyService function is named the same as the value registered on the module. Thus, the value will be injected into the service when it is created.

Providers Providers is the most flexible form of factory you can create. myModule.provider("mySecondService", function() { var provider = {}; provider.$get = function() { var service = {}; service.doIt = function() { console.log(“Service Done!"); } return service; } return provider; }); myModule.controller("MyController", function($scope, mySecondService) { $scope.whenButtonClicked = function() { mySecondService.doIt(); } }); $get() function creates whatever the provider creates (service, value etc.)

Configuring a provider myModule.provider("mySecondService", function() { var provider = {}; var config = { configParam : "default" }; provider.doConfig = function(configParam) { config.configParam = configParam; } provider.$get = function() { /* use config.configParam */} return provider; }); myModule.config( function(mySecondService) { // WON'T WORK -- mySecondService is an instance of a service – not provider mySecondService.doConfig("new config param"); });

Configuring a provider myModule.provider("mySecondService", function() { var provider = {}; var config = { configParam : "default" }; provider.doConfig = function(configParam) { config.configParam = configParam; } provider.$get = function() { /* use config.configParam */} return provider; }); myModule.config( function( mySecondServiceProvider ) { mySecondServiceProvider.doConfig("new config param"); }); myModule.controller("MyController", function($scope, mySecondService) { $scope.whenButtonClicked = function() { mySecondService.doIt(); } });

Constants myModule.constant("configValue", "constant config value"); myservices.config( function( mySecondServiceProvider, configValue ) { mySecondServiceProvider.doConfig(configValue); }); Constants in AngularJS are defined using the module.constants() function:

Dependencies Between Modules var myUtilModule = angular.module("myUtilModule", []); myUtilModule.value ("myValue", "12345"); var myOtherModule = angular.module("myOtherModule", ['myUtilModule']); myOtherModule.controller("MyController", function($scope, myValue) { });

Multi-module architecture

Using decorator: service example angular.module('thirdParty', []).service(' Service', function() { this. = ""; this.setContent = function(content) { this. = content; }; this.send = function(recipient) { return 'sending "' + this. + '" to ' + recipient; }; });

Using decorator to extend service var app = angular.module('myApp', ['thirdParty']); app.decorator(' Service', function($delegate) { $delegate.sendWithSignature = function(recipient, signature) { return 'sending "' + this. + '" to ' + recipient + " by " + signature; }; return $delegate; }); app.controller('MainCtrl', function($scope, Service) { Service.setContent("Greeting!!"); $scope. Complete = Service.sendWithSignature 'tamakisquare'); });

Using decorator to customize directive app.directive("user", function() { return { replace: true, template: ' This is foo directive ' }; }); app.decorator('userDirective', function($delegate) { var directive = $delegate[0]; directive.restrict = "AE"; return $delegate; }); Notice that we have to add postfix "Directive" original directive instance

Minification Safe Dependency Injection in AngularJS var myapp = angular.module("myapp", ['myservices']); myapp.controller("AController", ['$scope', '$http', function(p1, p2) { p1.myvar = "the value"; p2.get("/myservice.json"); }]); When you minify JavaScript the JavaScript minifier replaces the names of local variables and parameters with shorter names.

Internationalization {{theDate | date : "fullDate"}} {{theValue | currency }} var module = angular.module("myapp", []); module.controller("mycontroller", function($scope) { $scope.theDate = new Date(); $scope.theValue = ; }); date filter: short medium fullDate shortDate mediumDate longDate shortTime mediumTime number filter: {{ theValue|number }} currency filter: {{ theValue | currency : '£' }}

Cross-controller communication: events // dispatches the event upwards through the // parent controller scope hierarchy $scope.$emit('myCustomEvent', 'Data to send'); // broadcast dispatches the event downwards to all child scopes $scope.$broadcast('myCustomEvent', { someProp: 'Sending you an Object!' // any object }); // listening in any $scope $scope.$on('myCustomEvent', function (event, data) { console.log(data); });

Cross-controller communication: use services Controller can use service properties and methods for communication.

Summary