두 개의 선택 상자가 있고 상자 중 하나에 대한 옵션이 즉시로드되고 두 번째 (하위) 선택에 API를 쿼리하는 콜백에서 해당 옵션이 제공됩니다 . 부모가 선택한 값없이로드되는 레코드가 4200 개이므로 가능한 모든 옵션을 미리로드하는 옵션이 아닙니다. AngularJS : TypeError : undefined가 체인화 된 선택 항목이있는 함수가 아닙니다
친 박스 화재의 NG 변경 이벤트는 통화가 이루어질 때 : 가function CertificateSearchCtrl($q, CPSIAService) {
var vm = this;
vm.products = [];
vm.categories = [];
vm.certficate = {};
vm.categoryselect = {};
vm.productselect = {};
처음로드 컨트롤러에 직접 비아 NG-INIT 전화 또는 수
vm.loadCategories = function() {
CPSIAService.getCategories().then(function(results){
vm.categories = results;
});
};
또는 내가 같은 방식으로이 문제를 호출 할 수 있습니다 (NG-초기화 또는 컨트롤러를 통해 직접)
vm.findProducts = function(data) {
CPSIAService.getProductsByCategory(data.id).then(function(results){
vm.products = results;
});
};
...
그러나 나는 두 가지를 호출 할 수 없습니다 함께 컨트롤러를 통해 카테고리 변경을 통해 findProducts() 호출에 카테고리 ID를 강제로 변경하거나 직접 호출 할 수 있습니다.
이렇게하면 자식 선택에 "제품"배열을 채울 수 있습니다. 제어 HTML은 (출력이 지시어를 통해 인) 이것이다 : 나는 처음에 (오히려 NG 변경 이벤트를 통해 이상)를 선택 아동에 대한 옵션을로드하려고해도
<div class="small-12 medium-6">
<select ng-model="vm.categoryselect" ng-change="vm.findProducts(vm.categoryselect)" ng-options="categories.category for categories in vm.categories track by categories.id" ng-cloak>
<option value="">(choose a category)</option>
</select>
</div>
<div class="small-12 medium-6">
<select ng-model="vm.productselect" ng-change="vm.loadCertificate(vm.productselect)" ng-show="vm.products.length>0" ng-options="products.description for products in vm.products track by products.sku" ng-cloak>
<option value="">(select a product)</option>
</select>
</div>
- 저도 같은 오류가 . 다음은 Chrome 스택 추적입니다.
TypeError: undefined is not a function
at render (angular.js:25905)
at Scope.$get.Scope.$digest (angular.js:14280)
at Scope.scopePrototype.$digest (hint.js:1468)
at Scope.$get.Scope.$apply (angular.js:14493)
at Scope.scopePrototype.$apply (hint.js:1478)
at HTMLSelectElement.selectionChanged (angular.js:25657)
at HTMLSelectElement.eventHandler (angular.js:3011)angular.js:11598 (anonymous function)angular.js:8548 $getangular.js:14282 $get.Scope.$digesthint.js:1468 scopePrototype.$digestangular.js:14493 $get.Scope.$applyhint.js:1478 scopePrototype.$applyangular.js:25657 selectionChangedangular.js:3011 eventHandler
다음은 문제의 JSON 데이터 샘플입니다. 내가 linted/유효성을 검사하고 괜찮습니다.
[{"sku":"2004","description":"ADHSVE PAPR BLK BDR8CT-12"},{"sku":"2005","description":"ADHSVE PAPR BLU BDR8CT-12"},{"sku":"2006","description":"ADHSVE PAPR RED BDR8CT-12"},{"sku":"0043630-5987","description":"BORD 50 CS ASST 60 CT-1"},{"sku":"51671","description":"SLFSTK BORDER BLK 2X12-12"},{"sku":"51672","description":"SLFSTK BORDER BLU 2X12-12"},{"sku":"51673","description":"SLFSTK BORDER RED 2X12-12"}]
도움말!
경우에만 내 서비스를 한 번에 두 번 호출하려고 시도하지 않고 실제로 내 자녀를로드 할 수 있음을 알았습니다. 어쩌면 나는 약속을 오해하고있는 것일까? 나는 그것들이 .then() 함수로 해결할 것이라고 생각했지만, API 호출이 좋고 데이터가 예상대로 돌아 왔음에도 불구하고 두 번째 API를 완성하려고 할 때 오류가 발생한다. (위의 JSON 참조)
JQuery 오류에 영향을 미치지 않습니다. jQuery가 포함되거나 포함되지 않은 동일한 재생산이 포함됩니다.
어떤 AngularJS 버전을 사용하고 있습니까? – falsarella
1.3.11. 이전 버전에서이 문제를 1.3.5 이하로 재현 할 수 있습니다. – Fred
그래서'(angular.js : 25905)'는 .prop ('selected', option.selected)'에 해당합니다. – falsarella