var app = angular.module(‘myApp’, []);
app.factory(‘testFactory’, function(){
var testObject = {};
testObject.list = [];
var _setter = function (data) {
testObject.list.push(data);
};
var _getter = function () {
return testObject;
};
return {
setter: _setter,
getter: _getter
}
});
function InputCtrl(scope, testFactory)
{scope.input = {
name: ”,
age: null,
title: ”
};
$scope.addInput = function() {
testFactory.setter($scope.input);
$scope.input = {
name: '',
age: null,
title: ''
};
};
}
function OutputCtrl(scope, testFactory)
{scope.persons = testFactory.getter();
}