我有一个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
应该对此进行评估,我无法弄清楚它为什么不起作用。
答案 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
上的括号)