2016-03-21 18 views
1

Ebeveyn yönergesinin denetleyicisine erişen bir üst yönerge tarafından aktarılan bir alt yönergeye sahip olmak istiyorum. Ancak "testChild" yönergesi için gerekli olan "Controller 'testParent" hatası bulunamıyor;transclusion ve üst denetleyiciye erişme

app.directive('testParent', function(){ 
    return { 
    restrict :'E', 
    template: '<div>', 
    transclude:true, 
    controller: function(){ 
     this.log = function() { 
     console.log('test'); 
     } 
    }, 
    link : function(scope, element, attrs, unusedController, transcludeFn) { 
     element.append(transcludeFn()); 
    } 
    } 
}); 

app.directive('testChild', function(){ 
    return { 
    restrict : 'E', 
    template: '<div>Child</div>', 
    require:'^testParent', 
    link : function(scope, element, attrs, controller){ 
     controller.log(); 
    } 
    } 
}) 

http://plnkr.co/edit/miqH0r80G8bI0B5bAOzA?p=info

cevap

0

Sen transcludeFn kullanarak DOM olarak ekler olabilir DOM

transcludeFn(function(clone) { 
    element.append(clone); 
}); 

Demo PLunkr klonlanmış

+0

teşekkürler! Bana nasıl çalıştığını da söyleyebilir misin? – raichu

İlgili konular