Я следую примеру $ionicPopup.show здесь, но терплю неудачу.
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
нельзя изменить.
Может ли кто-нибудь помочь мне выяснить, в чем проблема?