2016-06-16 13 views
1

私はこのサービスを使ってjsonデータを取得しています。どのようにして2つのパラメータも渡すことができます。 jsonでは、私はドロップダウンに値を設定する必要があります。角度パラメータと受信json

 myApp.service('allCurrentSettingsService', ['$http', '$q', function ($http, $q) { 
     var allSettings = null; 
     this.getList = function() { 
      var def = $q.defer() 
      if (allSettings) { 
       def.resolve(allSettings); 
      } else { 
       $http.post('GetAllCurrentSettings', { companyName: compName, customerName: custName }) 
        .then(function (response) { 
         var response = $.parseJSON(response.data) 
         allSettings = response; 
         def.resolve(allSettings); 
        }); 
      } 
      return def.promise; 
     } 
    }]); 

そしてここで私は、サービスを呼び出すいます:

myApp.controller('myController', ['$scope', 'getDocTypesService', 
    function ($scope, getDocTypesService) { 
    $scope.getDocTypes = ''; 
    getDocTypesService.getList(compName, custName).then(function (value) { 
    $scope.getDocTypes = value 
    }); 
} 

]);

+0

を?クエリ? Urlパラメータ?体 ? – mfrachet

+0

は、角度からあなたのサービスへ、またはサービスから角度への2つのパラメータですか? – Manatax

+0

ありがとうございます。パラメータは、角度サービスから私のMVCコントローラに行く – user6440175

答えて

1

機能パラメータがありませんでした。関数定義に同じものを追加してください。

this.getList = function (compName, custName) { 
 
      var def = $q.defer() 
 
      if (allSettings) { 
 
       def.resolve(allSettings); 
 
      } else { 
 
       $http.post('GetAllCurrentSettings', { companyName: compName, customerName: custName }) 
 
        .then(function (response) { 
 
         var response = $.parseJSON(response.data) 
 
         allSettings = response; 
 
         def.resolve(allSettings); 
 
        }); 
 
      } 
 
      return def.promise; 
 
     }

また、他の方法で)($ http.postを呼び出すことができます。あなたはパラメータを追加したい

var data = {param:'val1',.....} 
 
    $http({ 
 
    url: "time.php", 
 
    method: "POST", 
 
    params: data 
 
    })

+0

私はそれを試みた(更新されたファイルを参照してください)が動作しませんでした – user6440175

+0

更新された答えを確認してください。 – Aravind

+0

ありがとうございます。サービスを呼び出すときにこれらのパラメータを追加する方法を教えてください。コードを追加しました。 – user6440175

関連する問題