ng 모델 중 하나는 Null 값을 제공합니다. 기능이 setNewRecord
인 버튼을 클릭하면 selectedDocument
매개 변수가 null입니다. 처음 두 매개 변수는 정확합니다. 자바 스크립트 코드도 추가되었습니다.Ng 모델에 액세스 할 수 없음
<form name="myForm" >
<div>
<select ng-model="selectedCompany">
<option value="">-- Select Company --</option>
<option data-ng-repeat="currentSetting in currentSettings" value={{currentSetting.SCACCode}}>{{currentSetting.SCACCode}}</option>
</select>
</div>
<div><input id="Text1" type="text" ng-model="enteredCustomer"/></div>
<div>
<select ng-model="selectedDocument" ng-click="getTypes(selectedCompany, enteredCustomer)">
<option value="">-- Select Doc type --</option>
<option data-ng-repeat="docSetting in docSettings" value="{{docSetting.Doc_Type}}">{{docSetting.Doc_Type}}</option>
</select>
</div>
<input id ="btnAdd" type="button" value="Add new record" ng-click="setNewRecord(selectedCompany, enteredCustomer,selectedDocument)"/>
자바 스크립트
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;
}
}]);
myApp.controller('myController', ['$scope', 'getDocTypesService',
function($scope, getDocTypesService) {
$scope.getTypes = function(comp, cust) {
getDocTypesService.getDocTypes(comp, cust).then(function(value) {
$scope.docSettings = value
});
};
}
]);
= " getTypes "를 선택하십시오. 옵션의 값은 다이제스트가 트리거되지 않으므로 다시 렌더링되지 않습니다. 이 문제를 해결할 수있는 ng-options (https://docs.angularjs.org/api/ng/directive/select)를 살펴보십시오. 그러나 자바 스크립트 코드가 없으면 그냥 짐작할 수 있습니다 ... –
컨트롤러 코드를 볼 수 있습니까? – jbrown
자바 스크립트 – user6440175