2016-06-17 2 views
0

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

} 
]); 
+0

= " getTypes "를 선택하십시오. 옵션의 값은 다이제스트가 트리거되지 않으므로 다시 렌더링되지 않습니다. 이 문제를 해결할 수있는 ng-options (https://docs.angularjs.org/api/ng/directive/select)를 살펴보십시오. 그러나 자바 스크립트 코드가 없으면 그냥 짐작할 수 있습니다 ... –

+0

컨트롤러 코드를 볼 수 있습니까? – jbrown

+0

자바 스크립트 – user6440175

답변

0

이 함께 selectedDocument의 선택을 교체하십시오 :

<select ng-model="selectedDocument" 
     ng-click="getTypes(selectedCompany, enteredCustomer)" 
     ng-options="docSetting.Doc_Type for docSetting in docSettings track by docSetting.Doc_Type"> 
</select> 
문제는 아마 NG 클릭에 docSettings를 가져 오는 될 것
+0

감사합니다. 하지만 작동하지 않습니다 - 여전히 null입니다. – user6440175

+0

select의 옵션에서 값으로 무엇을 볼 수 있습니까? –

+0

user6440175

관련 문제