Here's a service:
myApp.factory('myService', function() {
var test = 5;
return{
setTestVal: function(val){
test = val;
},
getTestVal: function(){
return test;
}
}
});
This is my controllers. One get the value and one sets it
function MyCtrl($scope, myService) {
$scope.test = myService.getTestVal();
}
function SetCtrl($scope, myService){
$scope.newTestVal = '';
$scope.setTestVal = function(val){
myService.setTestVal(val)
}
}
But the view is not updated when I set the value.
Fiddle: http://jsfiddle.net/HB7LU/7036/
Is this the wrong approach to setting and getting values?