|
| 1 | +<template name="api.session.html"> |
| 2 | + <div> |
| 3 | + <a href="https://github.com/Urigo/angular-meteor/edit/master/.docs/angular-meteor/client/views/api/api.session.html" |
| 4 | + class="btn btn-default btn-lg improve-button"> |
| 5 | + <i class="glyphicon glyphicon-edit"> </i>Improve this doc |
| 6 | + </a> |
| 7 | + |
| 8 | + <do-nothing> |
| 9 | + {{#markdown}} |
| 10 | + |
| 11 | +# $session |
| 12 | + |
| 13 | +A service that binds a scope variable to a Meteor Session variable. |
| 14 | + |
| 15 | +---- |
| 16 | + |
| 17 | +## Usage |
| 18 | + |
| 19 | + $session(sessionKey).bind(scope, model) |
| 20 | + |
| 21 | +### Arguments |
| 22 | + |
| 23 | +<table class="variables-matrix input-arguments"> |
| 24 | + <thead> |
| 25 | + <tr> |
| 26 | + <th>Param</th> |
| 27 | + <th>Type</th> |
| 28 | + <th>Details</th> |
| 29 | + <th>Required</th> |
| 30 | + </tr> |
| 31 | + </thead> |
| 32 | + <tbody> |
| 33 | + <tr> |
| 34 | + <td>sessionKey</td> |
| 35 | + <td><a href="https://docs.angularjs.org/guide/scope" class="label type-hint type-hint-string">string</a></td> |
| 36 | + <td><p>The name of the session variable</p></td> |
| 37 | + <td><a href="" class="label type-hint type-hint-array">Yes</a></td> |
| 38 | + </tr> |
| 39 | + <tr> |
| 40 | + <td>scope</td> |
| 41 | + <td><a href="https://docs.angularjs.org/guide/scope" class="label type-hint type-hint-regexp">Scope</a></td> |
| 42 | + <td><p>The scope the document will be bound to</p></td> |
| 43 | + <td><a href="" class="label type-hint type-hint-array">Yes</a></td> |
| 44 | + </tr> |
| 45 | + <tr> |
| 46 | + <td>model</td> |
| 47 | + <td><a href="" class="label type-hint type-hint-string">String</a></td> |
| 48 | + <td><p>The name of the scope's model variable that the document will be bound to</p></td> |
| 49 | + <td><a href="" class="label type-hint type-hint-array">Yes</a></td> |
| 50 | + </tr> |
| 51 | + </tbody> |
| 52 | +</table> |
| 53 | + |
| 54 | +---- |
| 55 | + |
| 56 | +## Example |
| 57 | + |
| 58 | + if (Meteor.isClient) { |
| 59 | + |
| 60 | + app.controller("detailCtrl", ['$scope', '$session', |
| 61 | + function($scope, $session){ |
| 62 | + |
| 63 | + $session('counter').bind($scope, 'counter'); |
| 64 | + |
| 65 | + Tracker.autorun(function () { |
| 66 | + console.log('angular counter changed', Session.get('counter')); |
| 67 | + }); |
| 68 | + |
| 69 | + }]); |
| 70 | + |
| 71 | + } |
| 72 | + |
| 73 | + Template.hello.events({ |
| 74 | + 'click button': function () { |
| 75 | + // increment the counter when button is clicked |
| 76 | + Session.set("counter", Session.get("counter") + 1); |
| 77 | + } |
| 78 | + }); |
| 79 | + |
| 80 | + } |
| 81 | + |
| 82 | + HTML |
| 83 | + |
| 84 | + <div ng-controller="MainCtrl"> |
| 85 | + angular counter = [[ counter ]] |
| 86 | + <button ng-click="counter=counter+1">Add angular counter</button> |
| 87 | + <button>Add Meteor counter</button> |
| 88 | + </div> |
| 89 | + |
| 90 | + {{/markdown}} |
| 91 | + </do-nothing> |
| 92 | + |
| 93 | + </div> |
| 94 | +</template> |
0 commit comments