如何在选项输入选项之前停止功能调用

时间:2016-05-16 02:45:39

标签: javascript angularjs

我的选择输入中有一个产品列表,我想要的是调用" duplicateGammeProduit"每次我从列表中选择一个产品时,都会发送该产品的ID,但我注意到在我选择任何选项之前调用了这个方法,这是我的代码:

<select ng-model="produitId" ng-change="duplicateGammeProduit(produitId)">
        <option ng-repeat="pi in listProduitUsed" value="{{pi.id}}">{{pi.reference}}</option>
    </select>

这是控制器代码:

.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();

}]);

所以如何在选项选择之前停止此通话,因为此通话 减慢我的应用程序 谢谢你的帮助

1 个答案:

答案 0 :(得分:2)

$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);
...

与我的评论相同的想法