Fork me on GitHub

autorun

This method is a wrapper of Tracker.autorun and shares exactly the same API.

The argument of this method is a callback, which will be called each time Autorun will be used.

The autorun method is part of the ReactiveContext, and available on every context and $scope and will stop automatically when when it's context ($scope) is destroyed.


Arguments

Name Type Details Required
runFunc Function The function to run. It receives one argument: the Computation object that will be returned. Yes

Example with getReactively:

myModule.controller('MyCtrl', ['$scope', '$reactive', function($scope, $reactive) {
  $reactive(this).attach($scope);

  this.myVar = 10;

  this.autorun(() => {
    console.log('Autorun!!', this.getReactively('myVar'));
  });

  this.myVar = 50; // This will cause the autorun function method to run again
}]);