[英]Angularjs $scope with parameter
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: 我是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>
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: 这里的想法是这样的:一旦选中了值为“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;
}
}
};
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
但问题是,这不起作用,我不知道我是否以正确的方式进行此操作,
$scope.field
是问题,如何将参数传递给$scope
Hope someone can help me. 希望可以有人帮帮我。 Thanks.
谢谢。
You can use ng-model
with the checkbox, then use ng-disabled
to listen to that model belonging to the checkboxes. 您可以将
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.