Javascript ng change with ng repeat on Select下拉菜单仅触发一次
这是我的控制器:Javascript ng change with ng repeat on Select下拉菜单仅触发一次,javascript,angularjs,Javascript,Angularjs,这是我的控制器: App.controller('LicenseController', ['$scope', 'licenseService', function($scope, licenseService) { var self = this; $scope.productTypes = {name:'', productID:''}; self.productTypes = {name:'', productID:''}; $s
App.controller('LicenseController', ['$scope', 'licenseService', function($scope, licenseService) {
var self = this;
$scope.productTypes = {name:'', productID:''};
self.productTypes = {name:'', productID:''};
$scope.selectedProduct = {name:'', productID:''};
$scope.productVersions = {productVersion:'', versionID:''};
self.productVersions = {productVersion:'', versionID:''};
$scope.fetchProductType = function(){
licenseService.fetchProductType()
.then(
function(d) {
self.productTypes = d;
$scope.productTypes = d;
console.log($scope.productTypes[1].name);
console.log($scope.productTypes[1].productID);
},
function(errResponse){
console.error('Error while fetching Currencies');
}
);
};
$scope.fetchProductType();
$scope.getProductVersions = function(){
console.log($scope.selectedProduct.productID);
licenseService.getProductVersions($scope.selectedProduct.productID)
.then(
function(d) {
$scope.productVersions = d;
self.productVersions = d;
console.log($scope.productVersions[1].productVersion);
console.log($scope.productVersions[1].versionID);
},
function(errResponse){
console.error('Error while creating User.');
}
);
};
}]);
和HTML:
<tr>
<td>
<label for="sel1">Product Type</label>
<select class="form-control" id="sel1" ng-model=productTypes ng-change="getProductVersions()">
<option ng-repeat="type in ctrl.productTypes" value="" >
{{type.name}}
</option>
</select>
</td>
</tr>
<tr>
<td>
<label for="sel1">Product Version</label>
<select class="form-control" id="ver" ng-model="productVersions" >
<option ng-repeat="version in ctrl.productVersions" value="" >
{{version.productVersion}}
</option>
</select>
</td>
</tr>
产品类型
{{type.name}
产品版本
{{version.productVersion}
ng更改仅在产品类型的第一次更改时触发一次。我还希望在更改时传递所选产品类型。有人能帮我怎么做吗?我遇到了类似的问题。我能够修复它的方法是使用ng options指令,而不是查看选项 以下是Angular的1.x文档中的一个示例:
<select ng-model="myColor" ng-options="color.name group by color.shade for color in colors">