Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9298747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:23:50+00:00 2026-06-18T22:23:50+00:00

After saving a resource in angular.js, I want to broadcast the changes so a

  • 0

After saving a resource in angular.js, I want to broadcast the changes so a list view can be updated.

    function EnvironmentCtrl($rootScope,  $scope, $location, $routeParams, environmentService) {
      environmentService.get($scope, $routeParams.id);
      $scope.id = $routeParams.id

      $scope.save = function(){
         $scope.environment.$save(function(data) {
           $rootScope.$broadcast("model-update");
         });
      } 
    }

   function NavController($scope, $http, $routeParams, environmentService) {
     environmentService.list($scope);
     $scope.$on("model-update", function(){
       environmentService.list(function(data){
         $scope.environments = data;
         console.log("update called", $scope.environments); 
       });
     });
   }

The communication between these controllers when EnvironmentCtrl.save is called works ok. The console.log gets called and the data returned to the callback by the service gets correctly set in the $scope.

The relevant part of my service looks like this:

 services.factory('environmentService', [ '$resource', function($resource) {
   var environmentService = {};

   environmentService.list = function(callback) {
     var url = "/service/environment/"
     $resource(url).query(function(data) {
       callback(data);
     });
    }
    return environmentService;
  } ]);

My view looks like:

  <li data-ng-repeat="env in environments">
    <a href="#/environment/{{env.id}}">{{env.name}}</a>
  </li>

But doesn’t get updated until a refresh.

This is all ‘within angular’ (as far as I see) and I would have thought that it would ‘just work’. I’ve tried calling $digest from within the callback. $apply complains a digest is already in progress.

Can anyone tell me why the view does not get updated?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T22:23:52+00:00Added an answer on June 18, 2026 at 10:23 pm

    I agree that by the time the event arrives the model should have been updated. It looks like a bug in angular.

    Till then you can emit the event inside a $timeout if that works for you.

    $timeout(function() {$rootScope.$broadcast("model-update");}, 0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Saving changes after table edit in SQL Server Management Studio I need
How can I get a record id after saving it into database. Which I
After saving a String value into memcached using the Danga client, I attempted to
How to disable auto Update Maven Dependencies after saving a pom.xml in Eclipse IDE
I have an Xpage page with a single Notes document datasource. After saving a
I have some javascript code that saves a cookie. However, if after saving the
after some processing my program shows a messagebox saying you can read a log
I have a nested resource: resources :users do resources :cust_uploads end After uploads are
After saving some values into the database, I am finding it difficult to print
After saving a rails model, I'd like to generate an md5 hash of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.