1
ng-repeat의 자체 버전을 구현하고 싶습니다. 하지만 어떻게 든 jquery 추가 메서드가 작동하지 않는 것 때문에 일을 얻을 수 없습니다.AngularJS에서 jquery append 메서드가 지시문에서 작동하지 않는 것 같습니다.
script.js :
var app = angular.module("app", []);
app.directive("myRepeat", function() {
return {
restrict: 'E',
compile: function(element, attrs) {
var c = element.children()[0];
console.log(c)
for(var i=0; i<attrs.times; i++) {
element.append(c);
}
return function(scope, element, attrs) {
$(element).click(function() {
console.log("hi");
})
}
}
}
})
index.html을 :
<body ng-app="app">
<my-repeat times="5"><p>hello world</p></my-repeat>
</body>
글을 편집했지만 다음 번에 글을 올렸습니다. SO에 코드를 게시하십시오. 코드를 읽으려면 다른 페이지로 이동하면 안됩니다. 예를 들어 답안을 작성하는 동일한 페이지에서 코드를 사용할 수 있다면 편리합니다. – timss
할 것입니다. 고마워요! – lkahtz