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

  • Home
  • SEARCH
  • 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 9225661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:38:06+00:00 2026-06-18T04:38:06+00:00

NOTE: the fiddle uses an old version of Angular, and that it’s not working

  • 0

NOTE: the fiddle uses an old version of Angular, and that it’s not working any more because as of 1.2 the Angular template engine does not handle promises transparently.

I’m looking into chaining promises to populate my scope, and then having the scope automatically update the dom.

I’m running into problems with this though.. If I call “then” on an already resolved promise, it creates a new promise (that will call the success function asynchronously but almost immediately). I think the problem is that we’ve already left the digest cycle by the time the success function is called, so the dom never updates.

Here is the code:

<div ng-controller="MyCtrl">
    Hello, {{name}}! <br/>
    {{name2}}<br/>
    <button ng-click="go()">Clickme</button><br/>
    {{name3}}
</div>

var myApp = angular.module('myApp',[]);

function MyCtrl($scope, $q) {
    var data = $q.defer();    
    setTimeout(function() {$scope.$apply(data.resolve("Some Data"))}, 2000);
    var p = data.promise;

    $scope.name = p.then(angular.uppercase);
    $scope.name2 = p.then(function(x) { return "Hi "+x;});
    $scope.go = function() {
            $scope.name3 = p.then(function(x) { 
                // uncomment this to make it work:
                //$scope.$apply();
                return "Finally: "+x;
            });
    };
 }

http://jsfiddle.net/QZM4d/

Is there some way to make this work without calling $apply every time I chain promises?

  • 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-18T04:38:07+00:00Added an answer on June 18, 2026 at 4:38 am

    NOTE: the fiddle uses an old version of Angular, and that it’s not working any more because as of 1.2 the Angular template engine does not handle promises transparently.

    To quote @pkozlowski.opensource:

    In AngularJS the results of promise resolution are propagated asynchronously, inside a $digest cycle. So, callbacks registered with then() will only be called upon entering a $digest cycle.

    So, when the button is clicked, we are in a digest cycle. then() creates a new promise, but the results of that then() will not be propagated until the next digest cycle, which never comes (because there is no $timeout, or $http, or DOM event to trigger one). If you add another button with ng-click that does nothing, then click that, it will cause a digest cycle and you’ll see the results:

    <button ng-click="">Force digest by clicking me</button><br/>
    

    Here’s a fiddle that does that.

    The fiddle also uses $timeout instead of setTimeout — then $apply() isn’t needed.

    Hopefully it is clear when you need to use $apply. Sometimes you do need to call it manually.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There's a working JS Fiddle that demonstrates Shadow DOM here . ( Note: There's
Note, this is not a duplicate of .prop() vs .attr() ; that question refers
Please take a look at the following fiddle: http://jsfiddle.net/ellenchristine/tty3e/ Note that when you expand
Note: please keep in mind that this is not a generic question on the
Here's a fiddle: http://jsfiddle.net/MZ9Xm/ Note: The following occurs in Chrome 22.0.1221.1, but not in
Link: http://hyperiontx.cbstage.com/ [note: I didn't make a fiddle because jsfiddle no longer seems to
note: I'm -not- trying to parse HTML with regex I'm trying to replace any
(Note: This is not a question about what is the best way with code
Note: I am not asking how to use Google Code's SVN repo as a
Note: Not sure if this is the right stack, please tell if I should

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.