如何使用动态模板创建指令?
'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>