나는 가지고있다
<tr ng-repeat="item in list">
<td>{{item.name}}</td>
<td><button ng-click="remove" is-disabled>Delete!</button></td>
</tr>
그리고 지시어 isDisabled
로
return {
link: function (scope, elm, attrs)
{
// get clicked row here
}
};
item
이 지시문에 어떻게 들어갈 수 있습니까? $scope.list
- $index
에서 사용할 수있는 항목 목록입니다. ng-repeat
올바른 방법입니까? 다른 해결책이 있습니까?
다음과 같이 상위 범위에 액세스하여 현재 항목에 액세스 할 수 있습니다.
scope.$parent.item
그러나 코드에서 긴밀한 결합 과 item 이라는 하드 코딩 된 속성 을 생성하므로 권장되지 않습니다 .
다음과 같이 지시문을 작성하십시오.
app.directive("isDisabled", function() {
return {
scope:{
item:"="
},
link: function(scope, elm, attrs) {
console.log(scope.item);
}
};
});
항목을 전달하십시오.
<tr ng-repeat="item in list">
<td>{{item.name}}</td>
<td>
<button ng-click="remove" is-disabled item="item">Delete!</button>
</td>
</tr>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다