Below is the script for Angular:
app = angular.module('app', [])
app.factory 'MyFactory', ->
val: 'Clark Kent'
app.controller 'MainCtrl', ($scope, MyFactory) ->
MyFactory.val = 'Waldo'
$scope.myFactory = MyFactory
Execute this code in your browser console:
angular.injector(['ng','app']).invoke(function(MyFactory) { console.log(MyFactory); })
Unexpectedly, instead of Waldo
, you will see Clark Kent
!!
Why is the returned object different?
For more details, visit this plunkr link