I am trying to implement the angular ng-repeat directive and I do not understand why this code is not working correctly.
.directive("myRepeat", function() { return { transclude: "element", priority: 1000, compile: function(tElem, tAttrs) { var myLoop = tAttrs.myRepeat, match = myLoop.match(/^\s*(.+)+in\s+(.*?)\s*(\s+track\s+by\s+(.+)\s*)?$/), indexString = match[1], collectionString = match[2], parent = tElem.parent(); return function($scope, iElem, iAttrs, controller, $transclude) { $scope.$watchCollection(collectionString, function(newCollection) { var i, block, elements = [];
and HTML snippet
<ul ng-controller="MyCtrl"> <li my-repeat="city in cities">{{city.name}}</li> </ul>
My problem is that the LI elements are displayed normally, but they do not contain city names. Please explain to me why this happens. I understand how ng-transclude works in the primitive case, when we have a template with an element with ng-transclude and specify transclude: true in our directive definition, but I donβt understand how this works with transclude: "element". PS Sorry for my English. I start:)
source share