Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularjs and Meteor "Session" reactivity, is there a way?
    primarykey
    data
    text
    <p>I'm trying to work with Meteor and Angularjs. I'm using <a href="https://github.com/lvbreda/Meteor_angularjs" rel="nofollow">Meteor_angularjs</a> package, which works OK with <code>Collections</code>.</p> <p>Now I'm trying to use <code>Session</code> and my reactive data store:</p> <pre><code>TestCtrl = [ "$scope", function($scope){ $scope.value = Session.get('someValue'); } ] </code></pre> <p>This does not work. </p> <p><strong>QUESTION:</strong> Any suggestions on how to tie down Meteor's <code>Session</code> and Angular? </p> <p>As far as I understand, I can write directive that will be polling <code>Session</code> every so ofter, however I don't think that's a good choice.<br> Thanks</p> <p><strong>UPDATE:</strong></p> <p>I've tried the following:</p> <pre><code>TestCtrl = [ "$scope", function($scope){ Meteor.autorun(function(){ $scope.config = Session.get('testsConfig'); if (!$scope.$$phase){ $scope.$digest(); } }); } ] </code></pre> <p>and it sort of works, however I get the following error:</p> <pre><code>Error: INVALID_STATE_ERR: DOM Exception 11 Error: An attempt was made to use an object that is not, or is no longer, usable. at derez (http://localhost:3000/test:95:41) at derez (http://localhost:3000/test:95:30) at derez (http://localhost:3000/test:95:30) at derez (http://localhost:3000/test:95:30) at derez (http://localhost:3000/test:95:30) at derez (http://localhost:3000/test:95:30) at derez (http://localhost:3000/test:95:30) at derez (http://localhost:3000/test:95:30) at derez (http://localhost:3000/test:95:30) at derez (http://localhost:3000/test:95:30) angular.js:5526 $get angular.js:5526 $get angular.js:4660 $get.Scope.$digest angular.js:7674 (anonymous function) controllers.js:46 Meteor.autorun.rerun deps-utils.js:78 _.extend.run deps.js:19 Meteor.autorun.rerun deps-utils.js:78 _.extend.flush deps.js:63 _.each._.forEach underscore.js:79 _.extend.flush deps.js:61 _.each._.forEach underscore.js:79 _.extend.flush deps.js:60 </code></pre> <p><strong>UPDATE 2:</strong></p> <p>I've tried the service like this (might be wrong usage), still nothing. Now it doesn't update at all on Session value's changes.</p> <pre><code>Meteor.autorun(function(){ app.factory('ssn', function(){ return{ get: function(val){ return Session.get(val); } }}); }); TestCtrl = [ "$scope","ssn", function($scope, ssn){ $scope.config = ssn.get('testsConfig'); } ] </code></pre> <p><strong>UPDATE 3</strong>: Angular has <a href="http://docs.angularjs.org/api/ng.%24rootScope.Scope#%24apply" rel="nofollow"><code>$apply()</code></a> for </p> <blockquote> <p>to execute an expression in angular from outside of the angular framework. (For example from browser DOM events, setTimeout, XHR or third party libraries)</p> </blockquote> <p>At the same time Meteor has <a href="http://docs.meteor.com/#meteor_render" rel="nofollow"><code>Meteor.render()</code></a> for </p> <blockquote> <p>Most of the time, though, you won't call these functions directly — you'll just use your favorite templating package, such as Handlebars or Jade. The render and renderList functions are intended for people that are implementing new templating systems.</p> </blockquote> <p>However, it seems like I just cannot put 2 and 2 together. :(</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload