5

यहाँ मेरी कोडTransclude लिंक समारोह में इंजेक्शन नहीं

है
'use strict'; 
angular.module('app') 
    .directive('item' 
      , ["$timeout" 
      , "$Service" 
      , function(
       $timeout 
       , $utils) { 
    return { 
     restrict: 'A', 
     scope: { 
      item: '=', 
     }, 
     transclude: true, 
     link: function(scope, element, attrs, ctrl, transclude){ 
     }, 
     templateUrl: $fsUtils.getRelativeUrl('templates/item.html'), 
     controller: 'ItemCtrl', 
    }; 
}]); 

मेरे index.html:

<item><div>Transcluded content.</div></item> 

transclude चर undefined है और ctrl चर proto__: Object है। मुझे पारदर्शी दायरे में मूल दायरे को इंजेक्ट करने की आवश्यकता है। Transclude चर अपरिभाषित है। मुझसे कहां गलती हो रही है।

मेरा कोणीय संस्करण 1.1.5

धन्यवाद।

+0

मैं 'item.html' देख सकते हैं? –

उत्तर

0

जो आप खोज रहे हैं वह transcludeFn है। इस प्रयास करें:

transclude: true, 
transcludeFn: function() { /*do your stuff here*/ }, 
... 
link: function(scope, element, attrs, controller, transcludeFn) 

लिंक समारोह में नियंत्रक आप ऐसा कर सकते पहुंचने के लिए:

var controller = scope.controller; 
+0

मैं समझता हूं कि ट्रांसफर को कोणीय द्वारा पूर्वनिर्धारित किया गया है, मेरे मामले में यह मेरे लिंक फ़ंक्शन में अपरिभाषित है। क्या समस्या है। –

+0

मेरा सवाल यह है कि आप इसे लिंक फ़ंक्शन में क्यों एक्सेस करना चाहते हैं? यह निर्देश परिभाषा का हिस्सा है और यह काम करेगा। क्या आप सशर्त रूप से स्थानांतरण को चालू/बंद करने की कोशिश कर रहे हैं? –

+0

मैं यह [यह] चाहता हूं (http://stackoverflow.com/questions/25641618/angular-transclude-ng-repeat-inside-directive#answer-27144559) –

संबंधित मुद्दे