Custom template and ng-click Angular Formally

I have a problem with a custom template that I created using Angular Formly. The template has one input text and two buttons to decrease and increases the value of the model of this input. The problem is that the down button works and reduces the model correctly, but the up button does not grow and instead performs the same $ scope.down () action. What am I wrong?

HTML template:

<span class="spinner"> <button class="button decrease" ng-click="down()"></button> <input type="text" ng-model="model[options.key]" name="{{options.key}}" /> <button class="button increase" ng-click="up()"></button> </span> 

Formal field:

 item.key = key; item.type = "my_spinner"; item.defaultValue = item.templateOptions.placeholder; item.controller = function($scope) { $scope.down = function () { $scope.model[$scope.options.key] = $scope.model[$scope.options.key] - 1; }; $scope.up = function () { $scope.model[$scope.options.key] = $scope.model[$scope.options.key] + 1; } }; } 

Update: the code in JSBin works http://jsbin.com/fakunoqeti/edit?html,js,console,output , so what could this be a problem? I need an angular-shaped expert D: D:

+5
source share
1 answer

why are your fields like that? this is not the right formal technique.

 { key: 'myKey', type: 'my_spinner', defaultValue: 'to.placeholder', templateOptions: { placeholder: 'myValue' }, controller: function($scope) { $scope.down = function () { $scope.model[$scope.options.key]--; }; $scope.up = function () { $scope.model[$scope.options.key]++; }; } } 

that the first place that I would start, put in the right format.

Then, if that doesn't work, I will pass the $ index property in the ng-click function: ng-click="up($index)" , and then change the function to $scope.up = function(index) {

0
source

Source: https://habr.com/ru/post/1247371/


All Articles