반응형
각도 지시어에 변수 전달
제가 지시가 있다면myDir
나는 그것을 '내부'라고 부른다.ng-repeat
그렇게
<my-dir myindex="{{$index}}"></my-dir>
접속 방법myindex
실제 스트링을 얻을 수 있습니다.{{$index}}
사용할 때attrs.myindex
이내에postLink
기능.html을 검사하면 실제로 다음과 같이 표시됩니다.myindex="2"
.
해라
<my-dir myindex="$index"></my-dir>
그리고나서
app.directive('myDir', function () {
return {
restrict: 'E',
scope: {
myindex: '='
},
template:'<div>{{myindex}}</div>',
link: function(scope, element, attrs){
scope.myindex = attrs.myindex;
console.log('test', scope.myindex)
}
};
})
데모: 플런커
언급URL : https://stackoverflow.com/questions/16432198/passing-variable-to-angular-directive
반응형
'programing' 카테고리의 다른 글
C#의 JSON 개체를 통해 반복하고 있습니다. (0) | 2023.03.23 |
---|---|
트위터 공유 URL의 get_the_title() 인코딩 (0) | 2023.03.23 |
바깥쪽 div 크기가 변경되면 스크롤 가능한 div를 바닥에 고정합니다. (0) | 2023.03.23 |
잭슨과 열거를 역직렬화하는 중 (0) | 2023.03.23 |
Postgre가 소개한 JSONB 설명SQL (0) | 2023.03.23 |