¿Cómo crear una directiva con una plantilla dinámica en AngularJS?
¿Cómo puedo crear una directiva con una plantilla dinámica?
'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>
Esto es lo que tengo ahora, y está mostrando la etiqueta correctamente. Sin embargo, no estoy seguro de cómo agregar HTML adicional a la plantilla. O combinando 2 plantillas en 1.