2016-06-17 2 views
0

Одна из ng-моделей дает нулевое значение. Когда я нажимаю кнопку с функцией setNewRecord, параметр selectedDocument имеет значение NULL. Первые два параметра верны. Добавлен код javascript.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)"/> 

Java Script

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

Проблема, вероятно, будет в выборке в docSettings на нг-клик =» getTypes "в списке. Значения в параметрах не будут перезагружаться, так как не будет активирован дайджест. Вы можете посмотреть ng-options (https://docs.angularjs.org/api/ng/directive/select), которые могли бы его решить. Однако без кода javascript я просто догадываюсь ... –

+0

Можем ли мы видеть ваш код контроллера? – jbrown

+0

Я добавил javascript – 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> 
+0

Спасибо. Но не работает - все равно null. – user6440175

+0

Что вы видите как значения внутри опций выбора? –

+0

<параметр data-ng-repeat = "docSetting in docSettings" value = "Test" class = "ng-binding ng-scope"> Тест – user6440175

Смежные вопросы