2016-06-17 13 views
0

角度サービスからmvcコントローラに2つの変数を送信しようとしています。そして、私はいつも間違いをしています。 compNameが存在しないというエラーが表示されます。私は数時間積み重ねられましたが、角度デバッガでデバッグしようとしましたが、これまでのところ運がありませんでした。 私のエラーには、角度コントローラがクリック時に代わりにサービスを呼び出そうとしているとは思いますが、それを修正する方法はわかりません。パラメータのエラーを伴う角度サービス

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

これは私の角度コントローラとサービスである: <select ng-model = "selectedDocument" ng-click="getDocTypes(selectedCompany, enteredCustomer)"> <option>Select document</option> <option ng-repeat="docSetting in docSettings" value=" {{docSetting.Doc_Type}}">{{docSetting.Doc_Type}}</option> </select>

+1

こんにちは、どういうエラーが出ているのか教えてください。 –

+0

クリックしてgetDocTypes関数を呼び出す場合は、コントローラのスコープで関数を定義する必要があります。 $ scope.getTypes = function(..){...}; – user3083618

答えて

2

を定義する必要があり、この:

コントローラ:

$scope.getTypes = function(comp, cust) { 
    getDocTypesService.getDocTypes(comp, cust).then(function (value) { 
      $scope.docSettings = value 
    }); 
}; 

テンプレート:

<select ng-model = "selectedDocument" ng-click="getTypes(selectedCompany, enteredCustomer)"> 

OBS:selectedCompanyとenteredCustomerは、前に定義された$スコープ変数でなければなりませんクリックが発生します。

+0

それは働いたのですか? –

1

.factory( 'MagComments'、関数($リソース){ リターン$:これは、HTMLで

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

      }) 

      }; 
     } 
     ]); 

リソース( 'http://localhost/dooleystand/ci/api/magCommenct/:id'、{ loginID:organEntity、 パスワード:organCommpassword、 id: '@magId' }) ; })

1

exixtではないパラメータスロー関数を渡しました。 あなたは試してみてください

$scope.getDocTypes = function(selectedCompany, enteredCustomer){ 
getDocTypesService.getDocTypes(selectedCompany, enteredCustomer).then(function (value) { 
      $scope.docSettings = value 

      }) 
} 
関連する問題