【问题标题】:why meteor subscribed collection is not accessible in angular function为什么在角度函数中无法访问流星订阅的集合
【发布时间】:2016-01-09 15:27:33
【问题描述】:

我正在使用流星开发一些应用程序,并为 ui 使用 angular,名为“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();
    }

【问题讨论】:

  • 您可以访问窗口吗? window['Foods'] 工作正常吗?

标签: angularjs meteor angular-meteor


【解决方案1】:

先尝试订阅收藏 this.subscribe() 在你的情况下 this.subsribe('食物')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-11
    • 2016-07-29
    • 2020-08-09
    • 1970-01-01
    • 2018-12-20
    • 1970-01-01
    • 1970-01-01
    • 2016-04-08
    相关资源
    最近更新 更多