Javascript 如何使用angular.js自动检查其他指令中的元素?
我有一个树结构,我正在尝试使用角度指令检查和取消检查。其思想是,当一个节点被选中时,它应该自动检查其中的元素。我的代码如下所示:Javascript 如何使用angular.js自动检查其他指令中的元素?,javascript,angularjs,angularjs-directive,Javascript,Angularjs,Angularjs Directive,我有一个树结构,我正在尝试使用角度指令检查和取消检查。其思想是,当一个节点被选中时,它应该自动检查其中的元素。我的代码如下所示: <div ng-repeat="actor in actors" style="margin-left: 46%;"> <div create-connections class="actor\{{$index}}" > <span><input class="checkbox-actor" type="c
<div ng-repeat="actor in actors" style="margin-left: 46%;">
<div create-connections class="actor\{{$index}}" >
<span><input class="checkbox-actor" type="checkbox" name="actor-checkbox" id="" ng-value ="actor" ng-model="checkBoxModel" actor-box >\{{actor}}</span>
<br/>
</div>
<div ng-repeat="activity in activities">
<div ng-if="actor == activity.id" style="margin-left: -40%;">
<div ng-repeat = "impact in activity.text" >
<div update-connections class="impact\{{$index}}actor\{{actors.indexOf(actor)}}" actor-id="actor\{{actors.indexOf(actor)}}" id="">
<span><input class="checkbox" type="checkbox" name="impact-checkbox" id="" value="">\{{impact}}</span>
</div>
<div ng-repeat="feature in features">
<div ng-if="actor == feature.id && impact == feature.key" style="margin-left: -25%;">
<div feature-connection ng-repeat = "feature in feature.text"class="feature\{{$index}}" activity-id="impact\{{activity.text.indexOf(impact)}}actor\{{actors.indexOf(actor)}}" id="">
<span><input class="checkbox" type="checkbox" name="impact-checkbox" id="" value="">\{{feature}}</span>
</div>
</div>
</div>
</div>
</div>
</div>
我还附上了截图
像这样使用:
link: function(scope, element, attrs) {
console.log("checking the checkbox");
element.find('input[type="checkbox"]').prop('checked',true);
console.log(element)
}
你的js尝试在哪里?添加了指令代码@BhojendraNepalIn,如果我的指令必须在父div上?我认为元素是输入的父元素..,你可以使用prop方法作为自己的目标。它不包括嵌套的复选框
link: function(scope, element, attrs) {
console.log("checking the checkbox");
element.find('input[type="checkbox"]').prop('checked',true);
console.log(element)
}