1

I'm new in Angular and I can't achieve something really simple, lets say we have several checkbox input loops followed by an input text field like this:

<body ng-app="ngToggle">
    <div ng-controller="AppCtrl">
        <input type="checkbox" ng-repeat="btn in btns" ng-model="changing" ng-change="change(btn.value, 'other')" class="here" value="{{btn.value}}">

        <input type="text" class="uncheck" ng-disabled="other">


    <!-- Here comes the other one -->

       <input type="checkbox" ng-repeat="btn in btns" ng-model="changing" ng-change="change(btn.value, 'other2')" class="here" value="{{btn.value}}">

       <input type="text" class="uncheck" ng-disabled="other2">
    </div>
</body>

And the idea in here is this: once the checkbox with value "other" is checked it will enable the corresponding text field determinate in the field parameter of the change function, so I develop a function change(value, field) and works like this:

     $scope.btns = [
        {value:'one'},
        {value:'two'},
        {value:'other'}
    ];

   $scope.other = true;
   $scope.other2 = true;

   $scope.change = function(value, field) {
    if(value == 'other'){
        if($scope.field == false){
        $scope.field = true;
      } else {
        $scope.field = false;
      }
    }
  };

But the problem is, this does not work, I don't know if I making this in the right way, the $scope.field is the problem, how can I pass a parameter to the $scope

Hope someone can help me. Thanks.

3
  • $scope.field does not seem to be initialized anywhere Commented Jun 6, 2016 at 14:57
  • Exactly, I'm trying to put the value in the passed parameter in the $scope, per example if I put something like this: change(one), the scope will become $scope.one because that's the FIELD parameter @Guillaume Commented Jun 6, 2016 at 15:02
  • right, I did not understand Commented Jun 6, 2016 at 15:04

1 Answer 1

0

You can use ng-model with the checkbox, then use ng-disabled to listen to that model belonging to the checkboxes.

<input type="checkbox" value="Other" ng-model="myCheckboxes['other']" />
<input type="text" ng-disabled="myCheckboxes['other']" />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.