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

$meteor.session

A service that binds an angular $scope variable to a Meteor Session variable, so it can be interacted (get, set) from within Angular modules as well as Meteor modules (templates).


$meteor.session has been deprecated in favor of of using regular Meteor Session directly without any wrappers.

Note that you are no longer be able to bind $scope to your session. if you are using sessions in order to get Reactive Vars, then it’s better that you will use reactive vars in scope getReactively.

Here is an example for how to migrate:

Old code:

angular.module(`myApp`, []).controller(`MyCtrl`, function($scope, $meteor) {
  $scope.myModel = 20;
  $meteor.session(`mySession`).bind($scope, `myModel`);
});

New code:

angular.module(`myApp`, []).controller(`MyCtrl`, function($scope) {
  Session.set(`mySession`, `myValue`);
  $scope.helpers({
    myModel() {
      return Session.get(`mySession`);
    }
  });
});

Usage

    $meteor.session(sessionKey).bind(scope, model)

Arguments

Param Type Details Required
sessionKey string

The name of the session variable

Yes
scope Scope

The scope the document will be bound to

Yes
model String

The name of the scope's model variable that the document will be bound to

Yes

Example

JavaScript:

if (Meteor.isClient) {

  app.controller("MainCtrl", ['$scope', '$meteor',
    function($scope, $meteor){

      $meteor.session('counter').bind($scope, 'counter');

      Tracker.autorun(function () {
        console.log('angular counter changed', Session.get('counter'));
      });

    }]);

  }

  Template.hello.events({ // change to variable from outside angular
    'click button': function () {
      // increment the counter when button is clicked
      Session.set("counter", Session.get("counter") + 1);
    }
  });

}

HTML:

    <div ng-controller="MainCtrl">
      angular counter = [[ counter ]]
      <button ng-click="counter=counter+1">Add angular counter</button>
      <button>Add Meteor counter</button>
    </div>