1
$rootScope.$on("conv", function() {
    var cobject = nservice.getconvo();
    console.log("cobject", cobject);

    $scope.cnotifications= cobject.convos;
    $scope.num_unread= cobject.num_unread;
});

This function is inside a controller.That controller is loading up only on page refresh.Its fethching the data from service when on page refresh.

5
  • What is the desired behavior? Commented Jul 8, 2014 at 17:21
  • i am getting notifications from service as the notifications will only get updated when the page refreshes Commented Jul 8, 2014 at 20:58
  • Your desired behavior is still unclear. Who will initiate the data refresh - the service will notify the controller that it has new data, or the controller will notify the service to refresh its data (and in turn refresh the data inside the controller)? Commented Jul 9, 2014 at 8:03
  • The service will notify the controller and in turn i need to refresh the controller or pass a trigger to activate the controller for updating values. Commented Jul 9, 2014 at 16:09
  • I can explain clearly that there are two controllers here.. one controller which updates the values coming from service..and it is used in the header part and the other controller which affects the body of the page.The header needs to refresh everytime when something changes in the body Commented Jul 9, 2014 at 16:10

1 Answer 1

1

Well, the simplest solution will be to use events. The service should have a method, which the controller calls, that tells the service to refresh the data (the notifications). Once fresh data is available in the service, the service will throw an event on the rootScope, which the relevant controllers will intercept, and update their models accordingly.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you.I used the service to tell the controller to refresh so it worked as you said

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.