为什么meteor订阅集合在角度函数中是不可访问的

时间:2016-01-09 15:27:33

标签: angularjs meteor angular-meteor

我正在使用流星开发一些应用程序,并使用角度为ui,这个名为' Foods'可以在循环中访问,但在openfooda函数中无法访问它,我无法弄清楚原因。

for (var i=0; i<FoodCategories.find().count(); i++) {
        $scope.groups[i] = {
            name: FoodCategories.find().fetch()[i]['title'],
            items: [],
            show : true,
        };

        for (var j=0; j < Foods.find({cat:i+1}).count(); j++) {
            $scope.groups[i].items.push({
                name:''+Foods.find({cat:i+1}).fetch()[j]['name'],
                id:''+Foods.find({cat:i+1}).fetch()[j]['id']});

        }

    }

    /**
     * this function opens a modal for getting user nutrition log
     */
    $scope.openfood = function(foodId){
        $scope.selectedfood = Foods.findOne({id : foodId});
        console.log(Foods.find().count());
        console.log(Foods.findOne({id : foodId}));
        $scope.unit = FoodUnits.findOne({id : $scope.selectedfood.unit})['title'] ;
        $scope.modal.show();
    }

1 个答案:

答案 0 :(得分:0)

首先尝试订阅收藏 this.subscribe() 在你的情况下 this.subsribe(&#39;食品&#39)