2016-07-21 8 views
7

द्वारा निर्धारित किया जाता कृपया इस Plunkerनिर्देशक के टेम्पलेट मूल्य नहीं मिलता है कि संकलन

मैं एक HTML कस्टम कोणीय निर्देश

<body ng-controller="myCtrl"> 
    <h1>Hello Plunker!</h1> 
    <div><sample attributeone="Sample Attribute"></sample></div> 
    </body> 

का उपयोग करता है और मेरे निर्देश इस तरह दिखता है:

myApp.directive('sample', function() { 
    var value = ""; 
     return { 
      replace: true, 
      restrict: 'E', 
      scope : false, 

      template: '<div>This is a sample Paragraph '+ value + '</div>', 

      compile: function (tElement, tAttributes) { 
       return { 
        pre: function preLink(scope, element, attributes) { 
         console.log(attributes.log + ' (pre-link)' ); 
         value = tAttributes.attributeone; 
        } 
       }; 
     } 
     }; 
}); 

मेरी राय में, precompile को बोफोरे निष्पादित करना चाहिए टेम्पलेट लौटाया गया है और value shou एलडी "Sample Attribute" पर सेट किया जाना चाहिए। लेकिन इसका मूल्यांकन नहीं हो रहा है।

अपेक्षित आउटपुट

This is a sample Paragraph Sample Attribute 

वास्तविक उत्पादन

This is a sample Paragraph 

वहाँ किसी भी अन्य तरीके जिसके माध्यम से मैं टेम्पलेट में value सेट है?

उत्तर

2

यदि आप value जोड़ना चाहते हैं, तो फ़ंक्शन के रूप में अपने टेम्पलेट का उपयोग क्यों न करें?

देखें इस अद्यतन Plunker

myApp.directive('sample', function() { 
    var value = ""; 
     return { 
      replace: true, 
      restrict: 'E', 
      scope : false, 

      template: function(ele, attr, ctrl) { 
       value = attr.attributeone; 
       return '<div>This is a sample Paragraph ' + value + '</div>'; 
      } 
     }; 
}); 
संबंधित मुद्दे