This API is deprecated since version 1.3.0 and no longer available since version 1.3.1

$scope.getReactively

A method to get a $scope variable and watch it reactively

$scope.getReactively has been deprecated in favor of the new getReactively API.


Usage

$scope.getReactively(scopeVariableName, objectEquality)

Arguments

Param Type Details Required Default
scopeVariableName string

The name of the scope's variable to bind to

Yes
objectEquality boolean

Watch the object equality using angular.equals instead of comparing for reference equality, deeper watch but also slower

No false

Returns

Reactive variable

A reactive variable that is binded to the scope variable and fires a changed event every time the scope variable changed


Example

$scope.sort = { name: 1 };

$scope.parties = $meteor.collection(function() {
  return Parties.find({}, {
    sort : $scope.getReactively('sort')     // Every time $scope.sort will change,
                                           // the reactive function will re-run again
  });
});


// Everytime one of the getReactively variables will change,
// the autorun will fire and the subscription will re-run
$meteor.autorun($scope, function() {
  $meteor.subscribe('parties', {
    limit: parseInt($scope.getReactively('perPage')),
    skip: (parseInt($scope.getReactively('page')) - 1) * parseInt($scope.getReactively('perPage')),
    sort: $scope.getReactively('sort')
  }).then(function() {

    console.log('new parties in page equals - ', $scope.parties);
  });
});

Example 2 - controllerAs syntax

When using the controllerAs syntax for controller naming and referencing in templates, also if you are using the angular2-now library, you will need to prefix the variable name with the name of your controller. That is, whatever name you supplied in controllerAs.

So, if controllerAs is vm then the following will work.

    limit: parseInt($scope.getReactively('vm.perPage')),
    skip: (parseInt($scope.getReactively('vm.page')) - 1) * parseInt($scope.getReactively('vm.perPage')),
    sort: $scope.getReactively('vm.sort')

Angular2-now always uses the controllerAs syntax internally and prefixes it's controllers with the camelCased version of your component's selector. If your component's selector is parties-list then the prefix will be partiesList and the code should look like this.

    limit: parseInt($scope.getReactively('partiesList.perPage')),
    skip: (parseInt($scope.getReactively('partiesList.page')) - 1) * parseInt($scope.getReactively('partiesList.perPage')),

$scope.getCollectionReactively

A method to get a $scope variable that will be a collection (not in terms of an AngularMeteorCollection).

This means dependencies will rerun if:

  • the variable is an object and properties are added or removed from the project
  • the variable is an array and elements are pushed or removed from the array.

This is more expensive than a simple getReactively("myVar") but still better than getReactively("myVar", true) as it does not need to compare the collection deeply during every digest. See the angular docs for further information.


Usage

$scope.getCollectionReactively(scopeVariableName)

Arguments

Param Type Details Required Default
scopeVariableName string

The name of the scope's variable to bind to

Yes

Returns

Reactive variable

A reactive variable that is binded to the scope variable and fires a changed event every time the scope variable changes or if new elements are added to or removed from the resolved object or array


Example

$scope.things = ["foo"];
$scope.$meteorAutorun(function(){
 var values = $scope.getCollectionReactively("things");
 console.log("values",values);
 //this runs everytime $scope.things.push(...)
});