Angularjs: Compile ng-repeat dynamically
问题 I have found some strange behavior with Angularjs. My directive simply adds and compiles ng-repeat to my dom element. However the scope variable item is not accessible. Look at the code below for explanation. var demo = angular.module('demo', []); demo.directive('customRepeat', function($compile) { return { priority: 2000, restrict: 'A', compile: function(element){ element.attr('ng-repeat', 'item in [1,2,3,4,5,6]') return function(scope, element) { $compile(element)(scope) } } } }); <script