Angular - Input1 Value Input2 same value when Checkbox is checked

后端 未结 3 613
忘掉有多难
忘掉有多难 2021-01-25 11:26

i have a problem, Here my code

相关标签:
3条回答
  • 2021-01-25 12:12

    You should use $scope.$watch to keep a look on the $scope.check variable. Once user click the checkbox, watchCheck would be invoked. Since you have defined the ng-true-value as "Yes", you have to check the checked ==== 'Yes' when the $scope.check changes.

    $scope.$watch('check', function watchCheck(checked) {
        if (checked === 'Yes') {
            $scope.nama1=$scope.nama;
            $scope.telephone1=$scope.telephone;
        }
    });
    
    0 讨论(0)
  • 2021-01-25 12:13

    Here is the plunker http://plnkr.co/edit/G4H4YfwTKO1jmiFDFIu6?p=preview var pesan = angular.module("pesan", []);

        pesan.controller("datapesan", function($scope){
    
          $scope.$watch('check',function(){
    
            if($scope.check){
               $scope.nama1=$scope.nama;
                $scope.telephone1=$scope.telephone;
            }
          });
    
    
    });
    
    0 讨论(0)
  • 2021-01-25 12:22

    Try this one;

        var pesan = angular.module("pesan", []);
    
            pesan.controller("datapesan", function($scope){
    
              $scope.$watch('check',function(){
    
                if($scope.check === 'Yes'){
                   $scope.nama1=$scope.nama;
                    $scope.telephone1=$scope.telephone;
                } else {
                    $scope.nama1='';
                    $scope.telephone1='';
                }
              });
    
    
        });
    
    0 讨论(0)
提交回复
热议问题