Angularjs dynamic directive inside ngrepeat

前端 未结 2 1469
一个人的身影
一个人的身影 2021-01-05 13:48

Look at example:

$scope.fields = [{
    name: \'Email\',
    dir : \"abc\"
}, {
    name: \'List\',
   dir : \"ffffd\"
}];

app.directive(\'abc\', function ()          


        
2条回答
  •  无人及你
    2021-01-05 14:16

    You could put this:

    
    

    also in a directive. You could construct this HTML string in JavaScript and attach it to the DOM. And you would also need to compile the resulting element using the $compile service, so that the dynamic directives will be compiled.

    Some dummy sample code (not tested, but should look something like this):

    app.directive('dynamicInput', function($compile){
    return {
        link: function(scope, element){
            var htmlString = '';
            element.replaceWith(htmlString);
            $compile(angular.element(element))(scope);
        }
    }
    

    });

    More info here.

提交回复
热议问题