繁体   English   中英

带参数的Angularjs $ scope

[英]Angularjs $scope with parameter

我是Angular的新手,我无法实现一些非常简单的东西,假设我们有几个复选框输入循环,后跟一个input文本字段,如下所示:

<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>

这里的想法是这样的:一旦选中了值为“other”的复选框,它将启用change函数的字段参数中确定的相应文本字段,因此我开发了一个函数change(value, field)并且像这样工作:

     $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;
      }
    }
  };

但问题是,这不起作用,我不知道我是否以正确的方式进行此操作, $scope.field是问题,如何将参数传递给$scope

希望可以有人帮帮我。 谢谢。

您可以将ng-model与复选框一起使用,然后使用ng-disabled来收听属于复选框的模型。

<input type="checkbox" value="Other" ng-model="myCheckboxes['other']" />
<input type="text" ng-disabled="myCheckboxes['other']" />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM