top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How many types of data binding in AngularJS?

+1 vote
348 views
How many types of data binding in AngularJS?
posted Aug 1, 2017 by Jdk

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

A factory is a simple function which allows you to add some logic before creating the object. In the end, it returns the created object.

Syntax.

app.factory('serviceName',function(){ return serviceObj;})

Creating Service Using The Factory Method.

JavaScript

 <script>
//creating module
 var app = angular.module('app', []);

 //define a factory using factory() function
app.factory('MyFactory', function () {
  var serviceObj = {};
 serviceObj.function1 = function () {
 //TO DO:
 };

 serviceObj.function2 = function () {
 //TO DO:
 };
 return serviceObj;
});
 </script>

When To Use Factory?

It is just a collection of functions, like a class. Hence, it can be instantiated in different controllers when you are using it with a constructor function.

answer Aug 3, 2017 by Manikandan J
...