There are two controllers. one controller will write data into an object & the other controller needs to read it. Can i have one global variable in my app.js file, that can be used in both the controllers. i am confused, why does one need to use service to share data between controllers? app.js::::::
var msg = 'message init'
app.controller('readController', function($scope){
$scope.msg = msg
console.log(msg)
});
app.controller('writeController', function(){
msg = 'message is written'
});
Doesn't the change made in write controller get reflected into the read controller? in that case, the console must have 'message is written'.