javascript - Acessing directive's scope within trancluded ng-repeat -


i'm writing component , need ng-repeat on directive's isolate scope property.

consider this:

<div some-directive>     <h2>let's repeat something</h2>     <p ng-repeat="item in contr.items">       title: {{ item.title }}        description: {{ item.desc }}     </p> </div> 

my idea directive provides collection of items (a resolve in real code, keep simple here). right have:

.directive('somedirective', function() {   return {     scope: {},     transclude: true,     template: '<div ng-transclude></div>',     controller: function($scope) {       $scope.items = this.items = [{         title: "item 1 title",         desc: "description"       }, {         title: "item 2 title",         desc: "another desc"       }, {         title: "item 3 title",         desc: "third desc"       }, {         title: "item 4 title",         desc: "third desc"       }];     },     controlleras: 'contr'   }; }); 

see this plunkr (and edit if like).

do have ideas?

it's design content added via ng-transclude binded outer (original) scope, not scope of current element ng-transclude on.

if want transcluded content binded isolate scope, use modified version of ng-tranclude this:

.directive('mytransclude', function () {   return {     restrict: 'eac',     link: function(scope, element, attrs, controllers, transcludefn) {       transcludefn(scope, function(nodes) {         element.empty();         element.append(nodes);       });     }   }; }); 

and use instead of ng-tranclude this:

template: '<div my-transclude></div>', 

example plunker: http://plnkr.co/edit/ydwuwcytazxyihjrgzoj?p=preview


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -