角度サービスから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>
こんにちは、どういうエラーが出ているのか教えてください。 –
クリックしてgetDocTypes関数を呼び出す場合は、コントローラのスコープで関数を定義する必要があります。 $ scope.getTypes = function(..){...}; – user3083618