服务中的多个功能不允许创建模块

时间:2017-01-24 21:44:44

标签: angularjs meanjs

我有一个CRUD模块activities而不是默认的articles,但模块的结构是相同的。

当我选择转到我创建新activity的页面时,会调用(例如activities.create一个

articles状态>
.state('activities.create', {
    url: '/create',
    templateUrl: 'modules/activities/client/views/form-activity.client.view.html',
    controller: 'ActivitiesController',
    controllerAs: 'vm',
    resolve: {
        activityResolve: newActivity
    },
    data: {
        roles: ['user', 'admin'],
        pageTitle: 'Activities Create'
    }
})

function newActivity(ActivitiesService) {
    return new ActivitiesService().getActivitiesOfAllUsers();
}

我的ActivitiesService看起来像这样:

function ActivitiesService($resource, Authentication) {
    return {
        getActivitiesOfCurrentUser: function() {
            return $resource('api/:userId/activities/:activityId', {
                userId: Authentication.user._id,
                activityId: '@_id'
            }, {
                update: {
                    method: 'PUT'
                }
            });
        },
        getActivitiesOfAllUsers: function() {
            return $resource('api/activities/:activityId', {
                activityId: '@_id'
            }, {
                update: {
                    method: 'PUT'
                }
            });
        }
    }
}

ActivitiesService的默认设置为:

function ActivitiesService($resource, Authentication) {
    return $resource('api/:userId/activities/:activityId', {
        userId: Authentication.user._id,
        activityId: '@_id'
    }, {
        update: {
            method: 'PUT'
        }
    });
}

newActivity函数看起来像这样:

function newActivity(ActivitiesService) {
    return new ActivitiesService();
}

因此,当服务处于默认布局时,转到创建页面就可以了。

但是,正如我所做的那样,为服务添加另一个功能就是打破它。当我选择转到创建页面时,没有错误,也没有迹象表明为什么没有发生任何事情。

从我所看到的情况来看,activityResolve应该对此进行评估,我无法弄清楚它为什么不起作用。

1 个答案:

答案 0 :(得分:0)

根据接受的答案here,我找到了答案。我将ActivitiesService修改为:

function ActivitiesService($resource, Authentication) {
    return {
        getActivitiesOfCurrentUser: $resource('api/:userId/activities/:activityId', {
                userId: Authentication.user._id,
                activityId: '@_id'
            }, {
                update: {
                    method: 'PUT'
                }
            }),
        getActivitiesOfAllUsers: $resource('api/activities/:activityId', {
                activityId: '@_id'
            }, {
                update: {
                    method: 'PUT'
                }
            })
    };
}

并将newActivity功能更改为:

function newActivity(ActivitiesService) {
    return new ActivitiesService.getActivitiesOfAllUsers;
}

(所以没有ActivitiesService上的括号)