How to write in 2 input simultaneously

0

I have the following doubt,

I have a form in which the user has to fill in the same information several times, so I want to add the functionality of checking a check to fill in X fields in all the input (for example the name, which is common)

Do you know if there is any angular functionality for this?

    
asked by Diego 13.03.2017 в 10:10
source

1 answer

4

I think the solution to what you are asking is to control the entry of the first box with the original value and then, depending on the value of the check, transfer it. I have prepared a small example that I think does what you ask.

var app = angular.module('myApp', []);

app.controller("myController", function($scope) {
  $scope.oneinput = "hola";
  $scope.writevalue = function() {
        if($scope.oneinput==true) {
          $scope.box2 = $scope.box1;
        }
      };
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myController">
<div>
  Caja1: <input type="text" ng-model="box1" ng-change="writevalue()">
  Repetir: <input type="checkbox" id="check" ng-model="oneinput" ng-init="false">
  </div>
  <div>
    Caja2: <input type="text" ng-model="box2">
  </div>  
</div>

I hope it serves you.

Greetings

    
answered by 13.03.2017 в 13:05