我在我的选择输入中有一个产品列表,我想要的是每次从列表中选择一个产品时调用“duplicateGammeProduit”,这将发送该产品的 ID,但我注意到的是在我选择任何选项之前调用方法,这是我的代码:
<select ng-model="produitId" ng-change="duplicateGammeProduit(produitId)">
<option ng-repeat="pi in listProduitUsed" value="{{pi.id}}">{{pi.reference}}</option>
</select>
这是 Controller 代码:
.controller(
'GammeCtrl', [
'$scope',
'$http',
function($scope, $http) {
$scope.duplicateGammeProduit = function(produitId) {
$http.get(MyURL:" +produitId).success(
function(gammeProduit) {
//the method to be called when an option is selected
$scope.classifierListElementGamme(gammeProduit.listElementGamme);
gammeProduit.id = null
....
$scope.finalOperationsList = gammeProduit.listElementGamme;
});
}
$scope.listeProduitUsed = function() {
$http
.get(URL/getProduitListUsed")
.success(
function(dataProduit) {
$scope.listProduitUsed = dataProduit;
});}
$scope.listeProduitUsed();
}]);
所以我怎样才能在选择选项之前停止这个调用,因为这个调用 减慢我的应用程序 谢谢帮助
最佳答案
$scope.duplicateGammeProduit = function(produitId) {
if (!produitId) {
return;
}
$http.get(MyURL:" +produitId).success(
function(gammeProduit) {
//the method to be called when an option is selected
$scope.classifierListElementGamme(gammeProduit.listElementGamme);
...
和我的评论一样
关于javascript - 如何在选择输入中选择选项之前停止函数调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37245999/