Angular: Empty Fiddle

http://angularjs.org/

by apimenov93

HTML

<script src="http://code.angularjs.org/angular-1.0.1.js"></script>
<div ng-controller="FactoryCtrl">
  <div ng-click="clickF()">
    click here{{countFactory}}!
  </div>
</div>

JavaScript

//angular.js example for factory vs service
var app = angular.module('myApp', []);

app.factory('testFactory', function(){
    var countF={};//= [{abc:'aaa'}];
    var getCountF = function(){
        return countF;
    };
    var setCountF = function(arg){
        countF = arg;
    };
    return {

        getCount : getCountF,
        setCount : setCountF,

        incrementCount:function(){
            //countF.push({aaaa:'jshfdkjsf'});
            countF={aaaa:'jshfdkjsf'};
            //return countF;
        }
    }
});

function FactoryCtrl($scope,testFactory)
{
    
    $scope.clickF = function () {
    		console.log("s");
        testFactory.incrementCount();
        $scope.countFactory = testFactory.getCount();
    };
}