1

Given the dart code

class LandingController {
  bool hideDiv = false;

  void doit() {
      new JsObject(context['loginControls']).callMethod('fadeLogin', [() {
         print(hideDiv);
         hideDiv = true;
         print(hideDiv);
         print("WTF");
      }]);
  }
}

which calls the JS:

var loginControls = function() {
  this.fadeLogin = function(func) {
    $('#landingHeader').animate({ opacity: 0 }, 500, func);
  }
};

which should affect the view:

<button ng-click="doit();">Click</button>
<div id="landingHeader">Hide me after button click</div>
<div ng-if="ctrl.hideDiv == false"><img src="assets/img/ajax-loader-small.gif">Waiting for div to disappear...</div>

After a button click and a 500 millisecond delay I see in my console a "WTF" print correctly. The div, however, is still visible. Once a user action occurs, in my case a mouse click, the div magically disappears. It seems as though the controller's value is changed, but the browser doesn't receive the change to hide the div, as I've printed the controller's value in the anonymous callback.

There is a work around, but it involves setting Dart timer's to the same fade times that you use in the javascript after the JsObject call and setting your controller's values in those Timer callbacks - gross but it works.

1 Answer 1

1

I think you need to call scope.apply(). I think Angular just can't recognize the value change in hideDiv when doit() is called from another zone (like JS).

You usually don't need to call scope.apply() in Angular.dart but I think this is one of the exceptions.

Is the animate function the only reason you use jQuery? It might be easier to do this with Angular.darts animation features.

3
  • This worked. Very silly of me to forget about scope.apply(), but I constantly do. Hope this helps someone. As an aside, while I'm currently only using it for animations this is just a mock site and may be expanded in the future. I did some research on this and found the pub package for animations but the missing features section drew me away from it.
    – Squiggler
    Nov 20, 2014 at 22:16
  • 1
    You know about Angular.darts own animation support? youtube.com/watch?v=EqilB8nJ6gE Nov 21, 2014 at 5:10
  • Well damn. Looks like I have some refactoring to do! Thanks!!
    – Squiggler
    Nov 21, 2014 at 20:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.