JSFiddle - React, Tailwind, and code Playground

by raji_rvr

HTML

<div ng-controller="HelloCtrl">
   
    <p>{{fromFactory}}</p>
</div>
<br />
<div ng-controller="GoodbyeCtrl">
    
    <p>{{fromFactory}}</p>
</div>

JavaScript

/angular.js example for factory vs service
var app = angular.module('myApp', []);
    
app.factory('testFactory', function(){
    return {
        sayHello: function(text){
            return "Factory says \"Hello " + text + "\"";
        },
        sayGoodbye: function(text){
            return "Factory says \"Goodbye " + text + "\"";
        }  
    }               
});

app.service('testService', function(){
    this.sayHello= function(text){
        return "Service says \"Hello " + text + "\"";
    };        
    this.sayGoodbye = function(text){
        return "Service says \"Goodbye " + text + "\"";
    };   
});

function HelloCtrl($scope, testService, testFactory)
{
    $scope.fromService = testService.sayHello("World");
    $scope.fromFactory = testFactory.sayHello("World");
}

function GoodbyeCtrl($scope, testService, testFactory)
{
    $scope.fromService = testService.sayGoodbye("World");
    $scope.fromFactory = testFactory.sayGoodbye("World");
}