R
R
Roman Rakzin2015-07-04 20:33:10
Angular
Roman Rakzin, 2015-07-04 20:33:10

When the data in the service changes, it does not change in the view.?

Previously, the data was stored in the controller and, if they were not updated by themselves, wrote
$scope.$apply ( function (results) {
$scope.resers = results;
});
Now I moved the code to the service, but the updated data is not visible in the view.
The service does not want to "inject" $scope - it swears.
What should I do to see the changed data?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
illeo, 2015-07-04
@illeo

The service must return a method, for example, getAll, which is called in the controller. It in turn gives an array of elements.
Inject the Service, then in the controller write
$scope.items = Service.getAll();

E
Eugene Kubesh, 2015-07-06
@Basters

In order for us to help you, you could take the trouble to give an example here of how you get data in a controller from a service and how you store/modify data in a service.
Otherwise, you can guess for a very long time

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question