[英]Dynamically Apply Attributes to DOM elements in ngRepeat in Directive
[英]Referencing DOM elements in dynamic table created with ngRepeat
我有一個動態生成的表。 每行包含一個select
(又名下拉菜單)和一個checkbox
。
在更改select
,我想另外更改checkbox
屬性,但是我不確定如何從ng-change
函數引用該checkbox
。
這是一個動態HTML表:
</table>
<tr ng-repeat = "(index, item) in items">
<td >
<select ng-model="item.myDropDown" ng-change="dropDownChange()">
<option value="A"> A </option>
<option value="B"> B </option>
</select>
</td>
<td>
<input type="checkbox" ng-model="item.myCheckbox" value="unchecked" disabled='disabled'/>
</td>
</tr>
</table>
現在,我嘗試使用以下方法在更改時引用這些元素:
myApp.controller('myController', function($scope) {
$scope.dropdownChange = function() {
console.debug(this.item.toDoDropdown); //I am able to reference the select-option values
document.getElementById(this.item.myCheckbox).checked = true; //This is placeholder code to signify my intent at referencing the checkbox
}
}
在我看來,該checkbox
不在此ngChange
函數的scope
,但是我不確定如何解決此問題。 此外,我試圖給每個表行自己的控制器上我的互聯網旅行,namingly建議在這里 ; 這確實是好習慣嗎?
您可以將索引和項目傳遞給方法: dropDownChange($index,item)
$scope.dropdownChange = function($index,item){
item.myCheckbox = true;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.