2017-03-08 91 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); 
      }); 
     } 
    } 
}) 

无论我输入customeDiscount任何价值,它总是给我0输出,使得价值$scope.customeDiscount不能改变。

有人可以帮我找出问题所在吗?

回答

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