AngularJS Custom Service Factory with Example

AngularJS Custom Service Factory with Example

In this Post We Will Explain About is AngularJS Custom Service Factory with Example With Example and Demo.Welcome on infinityknow.com – Examples,The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to AngularJS Custom Service and FactoryExample

In this post we will show you Best way to implement AngularJS Service Factory Tutorial, hear for Vuejs file upload example Step By Step with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

AngularJS service : Following List of four different ways

An AngularJS many ways to service can be new created and registered simple and created in following List of four different ways,
Anhularjs Provide the service() method
Anhularjs Provide the factory() method
Anhularjs Provide the provider() method
Anhularjs Provide the value() method
Anhularjs Provide the constant() method

READ :  Angular 6 Tutorial with Top 10 Examples

AngularJs Factory And Service Example



<title>
AngularJs Factory and Service Example
</title>
<a href="http://angular.min.js">http://angular.min.js</a>

var liveApp = angular.module('liveApp', []);
liveApp.factory('custFactory', function () {
	var displayFact;
		var addMSG = function (comments) {
		displayFact = ' Hi Friends, infinityknow.com Welcome to ' + comments;
		}
	return {
	yourmessageSet: function (comments) {
	addMSG(comments);
	},
	yourMessage: function () {
	return displayFact;
	}
	};
});

liveApp.service('cusServices', function () {
	var commentsdisp;
	var addMSG = function (comments) {
	commentsdisp = 'Hi Friends, infinityknow.com Welcome to ' + comments;
}

this.yourmessageSet = function (comments) {
	addMSG(comments);
}
this.yourMessage = function () {
return commentsdisp;
}
});
liveApp.controller("liveCtrl", function ($scope, cusServices, custFactory) {
	custFactory.yourmessageSet("Tutlane (with Factory)");
	cusServices.yourmessageSet("Tutlane (with Service)");
	$scope.mylistCustomers = [
	custFactory.yourMessage(),
	cusServices.yourMessage()
	];
});



<div>
<div>
{{coll}}
</div>
</div>


AngularJS internal services

module.controller('liveCtrl', function($http){
//Some Code...
});

module.controller('freeCtrl', function($window){
//Some Code...
});
 

AngularJS custom services Examples

var module = angular.module('liveApp', []);

module.service('clientService', function(){
	this.clients = ['raghav', 'deeep', 'man'];
});

AngularJS custom factory Method

module.factory('clientService', function(){
	
	var fac = {};
	
	fac.clients = ['raghav', 'deep', 'man']; 
	
	return fac;

});

AngularJS Service vs Factory Syntax

module.service( 'serviceName', function );

module.factory( 'factoryName', function );

AngularJS .service

module.service('atestService', function() {
this.firstchar = function() {
		//Angularjs Some code..
	}

this.secondchar = function() {
		//Angularjs Some code..
	}
});

AngularJS .factory

module.factory('atestService', function() {
var factory = {}; 
factory.firstchar = function() {
		//Angularjs Some code..
	}
factory.secondchar = function() {
		//Angularjs Some code..
	}
return factory;
});

Example

READ :  C# Armstrong Number Tutorial with Examples

I hope you have Got What is AngularJS Service Factory Tutorial And how it works.I would Like to have FeadBack From My Blog(infinityknow.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(infinityknow.com) Are Most Always Welcome.

Add a Comment

Your email address will not be published. Required fields are marked *