var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope, myFactory) {
$scope.name = 'World';
console.log(myFactory)
myFactory.setName("Plunker");
$scope.name = myFactory.name;
});
app.factory('myFactory', function () {
var factoryObj = {};
factoryObj.name = '';
factoryObj.setName = function (newName) {
factoryObj.name = newName;
}
return factoryObj;
});
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.2.x" src="https://code.angularjs.org/1.2.28/angular.js" data-semver="1.2.28"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<p>Hello {{name}}!</p>
</body>
</html>
/* Put your css in here */