【发布时间】:2015-04-08 11:30:52
【问题描述】:
我还没有找到挑战的答案或解决方案:如何在 angular-meteor 中反应性地绑定变量(会话变量,没有 mongo 集合)?
我正在从独立流星转换。在这里我可以使用 template.helper 方法。由于我不能再将模板(和 iron:router)与 angular-meteor 和 angularui-router 一起使用,我不能再将响应性绑定到帮助程序(至少在我的理解中)。
我在一个流星角度控制器中试过这个,它属于一个 sentence.tpl 文件:
$scope.parsestring = function(input_string){
tokenizer(input_string);
};
$scope.sentence_type = Session.getJSON("current_sentence.sentence_type");
标记化有效(我可以在调试器中看到它),但只有在我重新加载页面时才会显示该值。我想要实现的是将输入字段中的字符串标记为 JSON 表示(标记器负责处理)并以结构化方式从 JSON 表示中同时显示它(单独的 html 输入元素,它们是动态创建的)。 sentence_type 是应该在html页面上使用的变量,用于显示和更改句子类型,可以在键入时更改。
任何人有一些提示?也许,我也可以使用一些我不知道的 Angular 功能?
干杯, 一月
代码仓库:
我当前的代码如下所示:
My code looks similar to this:
angular.module('ngaignt').controller("InteractorCtrl", ['$scope', '$meteor', '$meteorCollection',
function ($scope, $meteor, $meteorCollection) {
// Autorun is necessary to make reactive variables out of the JSON returns
var c = Tracker.autorun(function (comp) {
$scope.verb_type = Session.getJSON("current_verb.type");
$scope.object_type = Session.getJSON("current_object.type");
$scope.verb_attributes = _.toArray(Session.getJSON("current_verb.attributes"));
$scope.object_attributes = _.toArray(Session.getJSON("current_object.attributes"));
if (!comp.firstRun) {
// only do not do aply at first run becaulse then apply is already running.
$scope.$apply();
}
});
$scope.parsestring = function (input_string) {
interactor(input_string);
};
//$scope.on('$destroy', function () {c.stop()});
}]);
【问题讨论】:
-
我看到有一个getReacivity (angularjs.meteor.com/api/getReactively) 方法,但它似乎仍然需要一个集合。
-
getReactively 可以接受任何 $scope 变量,无论是对象还是数组