2015-01-12 7 views
5

मान लें हम एक निर्देश के कॉन्फ़िगरेशन को परिभाषित करने के दो तरीके बनाने की जरूरत:कैसे एक निर्देश (एक और निर्देश के अंदर) की आवश्यकता के लिए केवल तभी मौजूद

1 - तत्व का उपयोग विशेषताओं

<any main-dir main-name="myname" name-id="may-id" main-other-config="other config"></any> 

2- एक और की आवश्यकता होती है निर्देश

app.directive("mainDirConfig", function() { 
    return { 
    controller: function (scope){ 
     scope.config = { 
     name: 'my name', 
     id: 'my-id', 
     otherConfigs: 'other config' 
     } 
    } 
    } 
}); 


<any main-dir main-dir-config></any> 

mainDirConfig निर्देश mainDir निर्देश (एक पसंदीदा तरीके के रूप में) के अंदर निर्देश की आवश्यकता है केवल mainDirConfig मौजूद है और अन्यथा तत्व गुणों को कॉन्फ़िगर के रूप में उपयोग करते हैं?

अधिक जानकारी: मैं बाहरी कॉन्फ़िगरेशन के लिए इस कॉन्फ़िगरेशन का उपयोग करना चाहता हूं और मुझे मॉड्यूल से उपयोगकर्ता कॉन्फ़िगरेशन को अलग करने की आवश्यकता है।

+0

की आवश्यकता है: "? वैकल्पिक माता-पिता" – setec

+1

@setec अच्छा! धन्यवाद। कृपया उत्तर के रूप में जोड़ें ताकि मैं इसे चिह्नित कर सकूं। – Reyraa

उत्तर

1

कोणीय प्रलेखन here से:

की आवश्यकता होती है

Require another directive and inject its controller as the fourth argument to the linking function. The require takes a string name (or array of strings) of the directive(s) to pass in. If an array is used, the injected argument will be an array in corresponding order. If no such directive can be found, or if the directive does not have a controller, then an error is raised. The name can be prefixed with: 

(no prefix) - Locate the required controller on the current element. Throw an error if not found. 
? - Attempt to locate the required controller or pass null to the link fn if not found. 
^ - Locate the required controller by searching the element and its parents. Throw an error if not found. 
^^ - Locate the required controller by searching the element's parents. Throw an error if not found. 
?^ - Attempt to locate the required controller by searching the element and its parents or pass null to the link fn if not found. 
?^^ - Attempt to locate the required controller by searching the element's parents, or pass null to the link fn if not found. 

यह निर्देश खंड में बताया गया है, लेकिन केवल पूरी तरह से $ संकलन अनुभाग में परिभाषित।

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