Replace ng-include node with template?

前端 未结 7 1000
感情败类
感情败类 2020-11-30 23:36

Kinda new to angular. Is it possible to replace the ng-include node with the contents of the included template? For example, with:

7条回答
  •  没有蜡笔的小新
    2020-11-30 23:58

    I would go with a safer solution than the one provided by @Brady Isom.

    I prefer to rely on the onload option given by ng-include to make sure the template is loaded before trying to remove it.

    .directive('foo', [function () {
        return {
            restrict: 'E', //Or whatever you need
            scope: true,
            template: '',
            link: function (scope, elem) {
                scope.replace = function () {
                    elem.replaceWith(elem.children());
                };
            }
        };
    }])
    

    No need for a second directive since everything is handled within the first one.

提交回复
热议问题