動的テンプレートを使用してディレクティブを作成するにはどうすればよいですか?
'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つに組み合わせます。