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!.

READ :  The Future of AngularJS Framework

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

AngularJs Factory And Service Example

[php]

<br /> AngularJs Factory and Service Example<br />
http://angular.min.js

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;
}
};
});

READ :  Angular 6 Tutorial with Top 10 Examples

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()
];
});

{{coll}}

[/php]

AngularJS internal services

[php]
module.controller(‘liveCtrl’, function($http){
//Some Code…
});

module.controller(‘freeCtrl’, function($window){
//Some Code…
});
[/php]

AngularJS custom services Examples

[php]
var module = angular.module(‘liveApp’, []);

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

[/php]

AngularJS custom factory Method

[php]
module.factory(‘clientService’, function(){

var fac = {};

fac.clients = [‘raghav’, ‘deep’, ‘man’];

return fac;

});
[/php]

AngularJS Service vs Factory Syntax

[php]
module.service( ‘serviceName’, function );

READ :  Angularjs MD5 Login and registration with php

module.factory( ‘factoryName’, function );
[/php]

AngularJS .service

[php]
module.service(‘atestService’, function() {
this.firstchar = function() {
//Angularjs Some code..
}

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

AngularJS .factory

[php]
module.factory(‘atestService’, function() {
var factory = {};
factory.firstchar = function() {
//Angularjs Some code..
}
factory.secondchar = function() {
//Angularjs Some code..
}
return factory;
});
[/php]

Example

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.

Leave a Reply

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