Harsha Kakumanu
Harsha Kakumanu

Reputation: 713

Angular js- Controller loads only on page refresh

$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.

Upvotes: 1

Views: 836

Answers (1)

Tom Teman
Tom Teman

Reputation: 2013

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.

Upvotes: 1

Related Questions