[英]chaining query with $resource
I have the following service which uses ngResource to set my syllableCount be clicking a button. 我有以下服务,该服务使用ngResource来设置我的syllableCount,方法是单击一个按钮。
//Words service used to communicate Words REST endpoints
(function () {
'use strict';
angular
.module('words')
.factory('querywordsService', querywordsService);
querywordsService.$inject = ['$resource'];
function querywordsService($resource) {
return $resource('api/words/?syllableCount=:count', {syllableCount: '@count'},
{
update: {
method: 'PUT'
}
});
}
})();
If the syllableCount button 2 is clicked the query shows the specific word. 如果单击syllableCount按钮2,则查询将显示特定单词。 This is how it looks in the Controller:
这是它在Controller中的外观:
$scope.searchCount = function (count) {
$scope.searchWords = querywordsService.query({count: count});
};
Everything works fine! 一切正常! But i need more than syllableCount inside the query.
但是我在查询中需要的不仅仅是syllableCount。 There are at least 4 other parameters that should go inside.
至少应包含4个其他参数。 If i just chain them like:
如果我像这样将它们链接起来:
api/words/?syllableCount=:count&?syllableStructur=:struct ....
its not working. 它不起作用。
Is there a good way to chain multiple queries like above? 是否有链接上述多个查询的好方法?
It works if i use it like this: 如果我这样使用它,它将起作用:
//Words service used to communicate Words REST endpoints
(function () {
'use strict';
angular
.module('words')
.factory('querywordsService', querywordsService);
querywordsService.$inject = ['$resource'];
function querywordsService($resource) {
var wordsData = $resource('/api/words/?syllableCount=:count&syllableStructur=:struct&frequency=:freq&emphasis=:emph',
{ count: '@count', struct: '@struct', freq: '@freq', emph: '@emph' },
{
update: {
method: 'PUT'
}
});
return {
wordsData: wordsData
};
}
})();
in the controller i set the different parameters to the value i need with ng-click from the buttons. 在控制器中,我可以通过单击ng-click按钮将不同的参数设置为所需的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.