ich viele Antworten auf diese sahen aber alle verwenden $scope
Ich habe mehrere ng-models
mit ein paar Tasten der erhöhen oder verringern Wert, möchte ich nur eine Funktion für alle verwenden.
So:
app = angular.module("myApp",[]);
app.controller("myCtrl", mainFunction);
function mainFunction(){
scope = this;
this.value1 = 3;
this.value2 = 5;
this.addOne = function (control) {
if (scope.control <12){
scope.control += 1;
}
}
this.dimOne = function (control) {
if (scope.control > 1) {
scope.control -= 1;
}
}
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl as vm">
<span>{{vm.value1}}</span>
<button ng-click="vm.dimOne('value1')">-</button>
<button ng-click="vm.addOne('value1')">+</button>
<br />
<span>{{vm.value2}}</span>
<button ng-click="vm.dimOne('value2')">-</button>
<button ng-click="vm.addOne('value2')">+</button>
</div>
Vielleicht könnten Sie die innere HTML der Spannweite ändern? –