Customizing the template within a Directive

前端 未结 4 1542
醉话见心
醉话见心 2020-11-28 00:25

I have a form that is using markup from Bootstrap, like the following:

Legend tex
4条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 01:03

    Here's what I ended up using.

    I'm very new to AngularJS, so would love to see better / alternative solutions.

    angular.module('formComponents', [])
        .directive('formInput', function() {
            return {
                restrict: 'E',
                scope: {},
                link: function(scope, element, attrs)
                {
                    var type = attrs.type || 'text';
                    var required = attrs.hasOwnProperty('required') ? "required='required'" : "";
                    var htmlText = '
    ' + '' + '
    ' + '' + '
    ' + '
    '; element.html(htmlText); } } })

    Example usage:

    
    
    
    

提交回复
热议问题