2017-03-08 12 views
0

私は$ionicPopup.show hereのサンプルに従いますが失敗します。ionicPopupは入力値を取得できません

angular.module('main').directive('dtDiscount', function($ionicPopup) { 
    return { 
     require: 'ngModel', 
     scope: { 
      operators: '=operators', 
      toggle: '=toggle', 
     }, 
     templateUrl: 'templates/components/discount.html', 
     link: function ($scope, $element, $attrs, ctrl) { 

      $scope.customeDiscount = 0; 
      $scope.setCustomDiscount = function(){ 
       $ionicPopup.show({ 
        title: 'Input Your Own Discount', 
        subTitle: 'XX %off', 
        template: '<input type="number" ng-model="customeDiscount"/>', // the preset value show 0, which is expected. 
        scope: $scope, 
        buttons: [{ text: 'Cancel' },{ 
         text: '<b>Confirm</b>', 
         type: 'button-positive', 
         onTap: function(e) { 
          console.log($scope.customeDiscount); // 0 
          return $scope.customeDiscount; 
         } 
        }] 
       }); 
      } 

      $scope.$watch('customeDiscount', function(value){ 
       console.log(value); 
      }); 
     } 
    } 
}) 

どのようなI入力customeDiscountための任意の値、それは常に値$scope.customeDiscountを変更できないように、私に0出力を提供します。

問題の原因を見つけるのを手伝ってくれる人がいますか?

答えて

1
//old $scope.customeDiscount = 0; 
$scope.data = {}; 

     $scope.setCustomDiscount = function(){ 
      $ionicPopup.show({ 
       title: 'Input Your Own Discount', 
       subTitle: 'XX %off', 
       template: '<input type="number" ng-model="data.customeDiscount"/>', // the preset value show 0, which is expected. 
       scope: $scope, 
       buttons: [{ text: 'Cancel' },{ 
        text: '<b>Confirm</b>', 
        type: 'button-positive', 
        onTap: function(e) { 
         console.log($scope.data.customeDiscount); // 0 
         return $scope.data.customeDiscount; 
        } 
       }] 
      }); 
     } 
+0

Thxをを使用し、それが役立ちます。この関数はデータでラップする必要があります。 – user3711105

0

2つの単純な値ではなくオブジェクトを使用しようとしましたか?

$scope.data= {} 

その後、

$scope.data.customeDiscount 
関連する問題