There are two controllers: one controller will write data into an object and the other controller needs to read it. Is it possible to have a global variable in my app.js file that can be accessed by both controllers? I'm unsure why one would need to use a service to share data between controllers.
var message = 'initial message'
app.controller('readController', function($scope){
$scope.message = message
console.log(message)
});
app.controller('writeController', function(){
message = 'message has been written'
});
Shouldn't the change made in the write controller be reflected in the read controller? In that case, the console should display 'message has been written'.