【问题标题】:chaining query with $resource使用 $resource 链接查询
【发布时间】:2016-08-04 18:27:22
【问题描述】:

我有以下服务,它使用 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'
      }
    });
  }
})();

如果单击 syllableCount 按钮 2,查询将显示特定单词。这是它在 Controller 中的样子:

    $scope.searchCount = function (count) {
      $scope.searchWords = querywordsService.query({count: count});
};

一切正常!但我在查询中需要的不仅仅是 syllableCount。至少还有 4 个其他参数应该放在里面。如果我只是像这样链接它们:

api/words/?syllableCount=:count&?syllableStructur=:struct .... 

它不工作。

有没有像上面那样链接多个查询的好方法?

【问题讨论】:

    标签: angularjs meanjs angular-resource angularjs-ng-resource


    【解决方案1】:

    如果我这样使用它就可以了:

        //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
          };
      }
    })();
    

    在控制器中,我通过 ng-click 按钮将不同的参数设置为我需要的值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-31
      • 1970-01-01
      • 1970-01-01
      • 2015-05-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多