How to use ng-repeat without an html element

后端 未结 8 1524
暖寄归人
暖寄归人 2020-11-30 23:35

I need to use ng-repeat (in AngularJS) to list all of the elements in an array.

The complication is that each element of the array will transform to ei

8条回答
  •  渐次进展
    2020-12-01 00:15

    for a solution that really works

    html

    
       html stuff in here including inner repeating loops if you want
    
    

    add an angular.js directive

    //remove directive
    (function(){
        var remove = function(){
    
            return {    
                restrict: "E",
                replace: true,
                link: function(scope, element, attrs, controller){
                    element.replaceWith('');
                }
            };
    
        };
        var module = angular.module("app" );
        module.directive('remove', [remove]);
    }());
    

    for a brief explanation,

    ng-repeat binds itself to the element and loops as it should, and because we have used ng-repeat-start / ng-repeat-end it loops a block of html not just an element.

    then the custom remove directive places the start and finish elements with

提交回复
热议问题