I have encountered an issue with updating a variable from one controller to another using a service. Despite my efforts, the variable is not being updated.
The goal is to have the variable $scope.names
in controller 'select' update in controller 'current' and display the updated information.
app.controller('select', ['$scope', '$http', 'myService', function($scope,$http, myService) {
$http.get('/myapp/stocknames').
success(function(data) {
$scope.names=data;
myService.names=data;
});
}]);
I am utilizing a service named myService to facilitate the exchange of data between the two controllers. The initialization of the names array within the service is done as follows:
app.service('myService', function($http, $rootScope) {
this.names=[]
});
app.controller('current', ['$scope', '$http', 'myService', function($scope,$http, myService) {
$scope.names=myService.names;
console.log($scope.names);
}]);
I am seeking assistance on how to ensure that the current controller reflects the updated data once the $scope.names
variable in the select controller has been updated.
Despite my best efforts, it seems like what I have implemented should work :-/