Ale*_*hko 5 angularjs meteor angular-meteor
我正在尝试使用Meteor和Angularjs.我正在使用Meteor_angularjs包,它可以正常使用Collections.
现在我正在尝试使用Session和我的反应数据存储:
TestCtrl = [
"$scope",
function($scope){
$scope.value = Session.get('someValue');
}
]
Run Code Online (Sandbox Code Playgroud)
这不起作用.
问题:关于如何绑定Meteor Session和Angular的任何建议?
据我所知,我可以编写指令,即将进行轮询Session,但我不认为这是一个不错的选择.
谢谢
更新:
我尝试过以下方法:
TestCtrl = [
"$scope",
function($scope){
Meteor.autorun(function(){
$scope.config = Session.get('testsConfig');
if (!$scope.$$phase){
$scope.$digest();
}
});
}
]
Run Code Online (Sandbox Code Playgroud)
它有点工作,但是我收到以下错误:
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
Run Code Online (Sandbox Code Playgroud)
更新2:
我已经尝试过这样的服务(可能是错误的用法),但仍然没有.现在它根本没有更新会话值的更改.
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');
}
]
Run Code Online (Sandbox Code Playgroud)
更新3:角有$apply()用于
从角度框架外部以角度执行表达式.(例如,来自浏览器DOM事件,setTimeout,XHR或第三方库)
同时流星有Meteor.render()用于
但是大多数情况下,你不会直接调用这些函数 - 你只需使用自己喜欢的模板包,如Handlebars或Jade.render和renderList函数适用于正在实现新模板系统的人员.
但是,似乎我不能把2和2放在一起.:(
这是一个带有旧答案的老问题,但我看到人们提到它,所以这里是更新的答案。
首先 - 有一个新图书馆可以为您处理这些情况。
这个库为您提供了两种可能的解决方案:
如果要将 Session 变量绑定到作用域变量,请使用$meteorSession服务。它的作用是,每次范围变量发生变化时,它都会更改为会话变量(如果将其放置在其中,则会触发自动运行)。每次 Session 变量发生变化时,作用域变量也会发生变化(并更改它所在的视图)。
如果您使用 Session 变量只是为了获得反应变量(意味着触发自动运行),则应该使用getReactively。这只是返回已经存在的范围变量,但每次更改时都会触发自动运行。我们的教程就是一个很好的例子。
| 归档时间: |
|
| 查看次数: |
1942 次 |
| 最近记录: |