1

独自のバージョンの ng-repeat を実装したいと考えています。しかし、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>

plkr.co で使用中のコード

4

1 に答える 1