Wie erstelle ich eine Direktive mit einer dynamischen Vorlage in AngularJS?
Wie kann ich eine Direktive mit einer dynamischen Vorlage erstellen?
'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>
Dies ist, was ich im Moment habe, und es zeigt das Etikett korrekt an. Ich bin mir jedoch nicht sicher, wie ich zusätzliches HTML an die Vorlage anhängen soll. Oder kombinieren Sie zwei Vorlagen zu einer.