मैं गतिशील टेम्पलेट के साथ निर्देश कैसे बना सकता हूं?कोणीय जेएस - निर्देश टेम्पलेट गतिशील
'use strict';
app.directive('ngFormField', function($compile) {
return {
transclude: true,
scope: {
label: '@'
},
template: '<label for="user_email">{{label}}</label>',
// append
replace: true,
// attribute restriction
restrict: 'E',
// linking method
link: function($scope, element, attrs) {
switch (attrs['type']) {
case "text":
// append input field to "template"
case "select":
// append select dropdown to "template"
}
}
}
});
<ng-form-field label="First Name" type="text"></ng-form-field>
यह वही है मैं अभी है, और इसे लेबल सही ढंग से प्रदर्शित किया जाता है। हालांकि, मुझे यकीन नहीं है कि टेम्पलेट में अतिरिक्त HTML कैसे जोड़ना है। या 2 टेम्पलेट्स को 1.
यह अपने उदाहरण सही ढंग से काम कर रहा है नहीं लगता है। क्या आप अनुसरण कर सकते हैं? – cdnicoll
संपादित करें: इसे काम कर रहा है, ऐसा लगता है कि यह बूटस्ट्रैप था। अपडेटेड लिंक: http://jsbin.com/wikocaru/2/edit – cdnicoll
उत्तरों में पूर्ण उदाहरण और कोड शामिल होना चाहिए, लिंक नहीं जो बाद में टूटी हुई लिंक समाप्त हो जाते हैं। – swenedo