Angularjs $ scope带参数 [英] Angularjs $scope with parameter

查看:147
本文介绍了Angularjs $ scope带参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Angular的新人,我不能实现一些非常简单的事情,让我们说几个checkbox输入循环后面跟一个输入文本字段像这样: / p>

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>

这里的想法是:一旦选中值为other的复选框,相应的文本字段在 change 函数的字段参数中确定,因此我开发一个函数 change(value,field)并且工作方式如下:

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

但问题是,这不工作,我不知道如果我在正确的方式, $ scope.field 是问题,我如何传递参数到 $ scope

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.

推荐答案

请参阅此链接,

Plnker.co

I hope it's help ful to you

这篇关于Angularjs $ scope带参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆