“选择”下拉菜单上的ng更改和ng重复只触发一次
ng-change with ng-repeat on Select drop down menu triggers only once
这是我的控制器:
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>
ng更改仅在产品类型的第一次更改时触发一次。我还想在更改时传递选定的产品类型。有人能帮我做这件事吗?
我遇到了类似的问题。我修复它的方法是使用ng选项指令,而不是查看选项。
以下是Angular的1.x文档中的一个示例:
<select ng-model="myColor" ng-options="color.name group by color.shade for color in colors">
https://docs.angularjs.org/api/ng/directive/ngOptions
相关文章:
- ng模型一次更改所有select
- 角度ng重复一次
- ng只重复添加项目一次
- 如何在一次有条件的ng单击时执行多个调用
- 为什么将 ng-select 替换为自定义指令会导致$http请求不会每隔一段时间发送一次
- Ng-Repeat只工作一次
- AngularJS指令在ng-repeat中为每个项目设置不同的值,只重复一次
- 可以一次又一次地使用 ng 重复吗?
- ng-change仅在ng-repeat内触发一次 - Angular
- NG-CLICK中的多个函数仅在函数上触发一次
- 只显示“;没有结果”;在AngularJS中使用嵌套ng repeat时一次
- 为什么一个ng应用程序一次工作
- AngularJS-只对ng更改触发$timeout事件一次
- ng重复计数-筛选器更新次数不超过一次
- 为什么Angular.js在ng更改时如此频繁地调用我的函数,以及如何使它每次更改只调用一次
- AngularJS ng-include只有一次
- 在获得一次事件后删除ng单击事件
- Ng-pattern regex查找只出现一次的模式
- Highcharts NG一次只显示一个点.动画
- Angularjs-ng更改和$scope$只看一次火